Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms - ListView entirely in XAML

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>
like image 340
jonathanpeppers Avatar asked Jun 26 '14 20:06

jonathanpeppers


People also ask

What is the difference between ListView and CollectionView in xamarin forms?

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.

What is ListView in xamarin forms?

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.

What is StackLayout in xamarin forms?

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.


1 Answers

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).

like image 196
WickedW Avatar answered Oct 24 '22 04:10

WickedW