Any similar "ListView" UI Control in Xamarin.Mac? - c#

I'm planning to design an multiple file downloader app (similar to IDM or Transmission) for macOS based on Aria2 JSON-RPC and C# GUI via Xamarin.Mac. But there is a major issue for UI design. I need a UI control which is similar to "ListView" in XAML.
Basically it's something like in this topic discussed, i.e. I need something equivalent in Xamarin.Mac with this XAML code below:
<ListView x:Name="DownloadItemList">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding DownloadItemTitle}"
Margin="20,0,20,8"
FontSize="24"
FontStyle="Italic"
FontWeight="SemiBold"
Foreground="DarkBlue" />
<TextBlock Text="{Binding DownloadProgressInfo}"
Margin="20,0,20,8"
FontSize="16"
Foreground="DarkGray"
Opacity="0.8" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I also need some data bindings in the UI code if possible. But so far I can't find any similar stuff in Xamarin.Mac. Is there any possible solution like this? Thanks in advance!

You can use NSTableView
static Content :
You can design cells from storyboard, and if required can modify content of these cells at runtime.
Dynamic Content : You can crate template cell at design time (or progrmmatically id requried ), give it identifier and use that cell multiple-time in tableviewd atasource.

You can use something like a table view
Hope this helps.
Link

Related

Can't get custom fonts to display at runtime - Windows Phone 8.1 MVVM - FontAwesome

I am having trouble with custom fonts in my Windows Phone 8.1 MVVM app.
I am using FontAwesome icons. I have included the FontAwesome font file in my project. When I set a static control such as this, it works perfectly;
<TextBlock x:Name="txtTest" Grid.Row="3" Text="" Foreground="Black" FontSize="20" FontFamily="/Assets/Fonts/FontAwesome.ttf#FontAwesome"/>
However, what I need is for this to work dynamically. I have a Hub control on the main page of the app, with ListViews in each Hub section. These are bound to a collection of custom objects, populated from an API response. When creating the collection of objects, the code looks for a marker in the response and dynamically sets the FontAwesome icon depending on the marker.
Hub Section code:
<HubSection x:Uid="hubApproved" Header="Approved"
DataContext="{Binding MyObjects.Approved}"
d:DataContext="{Binding MyObjects.Approved}"
HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}" >
<DataTemplate>
<ListView
ItemsSource="{Binding}"
ItemTemplate="{ThemeResource ApprovedTemplate}"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
</ListView>
</DataTemplate>
</HubSection>
And here is the Approved Template which binds to this:
<DataTemplate x:Key="ApprovedTemplate">
<StackPanel Margin="0,0,0,19" Background="{x:Null}" >
<TextBlock FontFamily="/Assets/Fonts/FontAwesome.ttf#FontAwesome" Text="{Binding Icon}" Foreground="Black" />
<TextBlock Text="{Binding SupplierName}" Style="{ThemeResource ListViewItemTripNameTextBlockStyle}" />
<TextBlock Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" Text="{Binding StartDate}"></TextBlock>
</StackPanel>
</DataTemplate>
The Template contains a TextBlock which binds to the Icon property of my object. This is supposed to then display the appropriate FontAwesome icon, but instead just displays the unicode of the icon:
I have tried defining the font family of the Hub control from the code behind in the view, but it has no effect:
Hub.FontFamily = new FontFamily("ms-appx:///Assets/Fonts/FontAwesome.otf#FontAwesome");
Any ideas on how to dynamically get these icons to display...? Thanks
You should be able to do it like this:
FontFamily fontFam = new FontFamily("ms-appx:///Assets/Fonts/FontAwesome.otf#FontAwesome");
and set FontFamily like this:
Hub.FontFamily = fontFam
I solved this with a workaround. The icons in my ListView will only ever be 1 of 5 possible icons. So instead of setting the unicode, I created 5 different textbox objects in the template definition, one for each icon. The unicode is static, so the dynamic aspect is instead the Visibility of each object. I created corresponding XAML Visibility properties on the custom object. After this, the style object is bound to its Visibility property, like so:
<!--Generic (shopping cart icon)-->
<TextBlock FontFamily="/Assets/Fonts/FontAwesome.otf#FontAwesome" Grid.Column="0" Text="" Style="{ThemeResource ListViewItemTripNameTextBlockStyle}"
VerticalAlignment="Center" Visibility="{Binding VisGeneric}" />
Then when I create the object collection from the API response, I set the appropriate visibility property to be Visible, according the the marker in the response.
I'd like a slightly more elegant solution than this, but essentially it works...

Generic UserControl Using Reflection and Generalization

in my project i've wrote some UserControl, i'm trying to reuse code as much as possible.
For each Model in my project i create an UserControl that shows the CRUD (a simple form ) and another that shows the List (listBox)
Is possible to Generalize that (for different types of Models with different attributes)?
Using Generalizatione and Reflection is possible to create something like a generic UserControl_Crud and generic UserControl_List?
So in my page.xaml i can use something like
<LUC:UserContro_Crud l x:Name="EmployeeUserControl_List" />
<LUC:UserContro_Crud l x:Name="CarsUserControl_List" />
<LUC:UserContro_Crud l x:Name="FruitUserControl_List" />
and in the code behind
EmployeeUserControl_List.MyProperty.ItemsSource = EmployeetList;
CarsUserControl_List.MyProperty.ItemsSource = CarstList;
//MyProperty give me back just the listbox from my UserControl
or
FruitUserControl_List.MyProperty.ItemsSource = EmployeetList;
to show 3 lists with differnt properties
#HighCore #Nate Diamond
In that way, for any kind of my Model, i have to make a particular template. For example CrudPersonTemplate `
<!-- my crud-->
<DataTemplate x:Key="MyCrud">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBlock Text="Code"/>
<TextBox x:Name="edtCode" InputScope="Number" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBlock Text="Name" />
<TextBox x:Name="edtName" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBlock Text="Sex" />
<TextBox x:Name="edtSex" />
</StackPanel>
</StackPanel>
</DataTemplate>
than (afeter registered it in the app.xaml as a resource) i can use it in Page.xaml just typing someting like
<ContentControl x:Name="MyTemplate" Content="{Binding}" ContentTemplate="{StaticResource MyCrud}" />
... but it's hard to manage field like "edtName" from page.xaml.cs or not? i have to write more code than using UserControl to do that...
How can I manage as well as possible this field of my form?
where is the difference with UserControl? i have to bind manually the ContentTemplate...
I'm looking for a generic solution in page.xaml, in the "view" i just want to call a generic template/userControl, and "automatically" choose the relative layout according with the object type associated in page.xaml.cs (i hope to explain it better, i apologize for my ignorance)

Declaring a string variable to a Textblock in Windows Metro

I might be a bit stupid asking this question. But i have not found anything on the net as of yet with my problem. I have a windows app, a listview displaying Texblocks with names in them and is loaded from a xml file. Here is the xaml code.
<ListView x:Name="listMyLoans" RenderTransformOrigin="0.446,0.54"
Margin="10,150,1052,10"
SelectionChanged="listMyLoans_SelectionChanged_1"
Grid.RowSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="300" Height="100" >
<TextBlock x:Name="tbTitle" Text="{Binding Title}"></TextBlock >
<TextBlock x:Name="tbMediaIndex" Text="{Binding MediaIndex}"
Visibility="Collapsed"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
and I need to declare it like to so in code behind.
string strMediaIndex = tbMediaIndex.Text;
Something like this but does not work, somehow does not see the TextBlock at all.
Thanks
You can use Tag property, so you dont have to declare two textbox.
Add a new eventhandler to this textbox OnTapped.
And in the Eventhandler you can cast the sender into textBox. When you cast it, you can grab the Tag element and you are ready. Simple and elegant if you are want to use the code-behind.

LongListSelector with two ItemTemplate

I use this code to add ListBox to my app:
<phone:LongListSelector x:Name="searchList" Margin="0,72,0,0" SelectionChanged="DidPressSelectSearchList">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
<TextBlock Text="{Binding}" FontSize="25" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Now my issue is that i want to use two kind of ItemTemplate, because there is two ways i show data to the user:
1) Array of Strings
2) Array of objects(2 Strings)
Any help how i can use the list to show two kind of objects?
The easiest way to do this in WP7 is with a Template Selector.
Like this one
Though I cant test it right now, WP8 should support the DataType property on the DataTemplate class, which means you can define implicit Data Templates for each data type and skip the selector altogether.

Multi Silverlight databinding

Does anyone know if its possible to do a binding and (if not how to achieve the same effect) on the same property using more than one binding in sort of a template
i.e.
A textblock that has Text bound in the expression
"{Binding Path=Contact.Title} {Binding Path=Contact.Firstname} {Binding Path=Contact.Surname}"
all in one text property
Not a big deal just:
<TextBlock>
<Run Text="{Binding Path=Contact.Title}"/>
<Run Text="{Binding Path=Contact.Firstname}"/>
<Run Text="{Binding Path=Contact.Surname}"/>
</TextBlock>
AFAIK it's not possible.
This is one of the reasons to follow the MVVM pattern, create an intermediary view which reflects the data in a format that you actually want presented, so you would create a fullname property on that class that was a concatenation of those fields and then bind to that.
Value Converters are one solution for binding to multiple values:
http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx#11262
In that scenario you'd bind your TextBlock's Text property to the Contact object and specify a custom value converter that you've created. The converter can perform the string formatting based on property values.
I don't think it is possible to do it directly in xaml. I would absolutely love multiple bindings to one property.
What I have learned however, is that you can accomplish things similar to this using a couple different strategies:
Using a Stackpanel:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hello, "/>
<TextBlock Text="{Binding Contact.Title}"/>
<TextBlock Text="{Binding Contact.Firstname}"/>
<TextBlock Text="{Binding Contact.Surname}"/>
<TextBlock Text="!"/>
</StackPanel>
Using a Converter:
<TextBlock Text="{Binding Contact,
Converter={StaticResource ContactNameConverter}}"/>
More Info On Converters

Categories