We have a few screens that should effectively be UITableViews
on iOS that have a static number of rows and different types of cells.
Is there a way to define this in XAML with Xamarin.Forms, and not have to setup a binding to ItemsSource
? Like if I just want to define two EntryCells
and then a TextCell
?
My first attempt is this example, but I just see the equivalent of Cell.ToString()
in each row:
<ListView>
<ListView.ItemsSource>
<x:Array Type="{x:Type Cell}">
<EntryCell Text="{Binding Phone}" />
<EntryCell Text="{Binding Code}" />
<TextCell Text="LOGIN" Command="{Binding Login}"/>
</x:Array>
</ListView.ItemsSource>
</ListView>
While the CollectionView and ListView APIs are similar, there are some notable differences: CollectionView has a flexible layout model, which allows data to be presented vertically or horizontally, in a list or a grid. CollectionView supports single and multiple selection. CollectionView has no concept of cells.
The ListView class supports a number of interaction styles. Pull-to-refresh allows the user to pull the ListView down to refresh the contents. Context actions allow the developer to specify custom actions on individual list items. For example, you can implement swipe-to-action on iOS, or long-tap actions on Android.
StackLayout organizes views in a one-dimensional line ("stack"), either horizontally or vertically. Views in a StackLayout can be sized based on the space in the layout, using layout options.
Considering you want static cells with different templates / layout for each cell, have you tried Xamarin.Forms TableView? http://iosapi.xamarin.com/?link=T%3aXamarin.Forms.TableView
<TableView>
<TableView.Root>
<TableSection Title="Login">
<EntryCell Text="{Binding Phone}" />
<EntryCell Text="{Binding Code}" />
<TextCell Text="LOGIN" Command="{Binding Login}"/>
</TableSection>
</TableView.Root>
</TableView>
Admittedly this seems to give you a non customisable section header at the time of writing (but this will probably improve).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With