Hello BindableLayout

it was really annoying that you only have to use listview for your collections. Now, you can use BindableLayout with Xamarin.Forms 3.5.0 pre2.

You can use it for all objects derived from Layout<T> (AbsoluteLayout, FlexLayout, Grid, RelativeLayout, and StackLayout)

public class StackLayout : Layout<View>

Let’s start with simple usage

<ContentPage.Content>
        <StackLayout BindableLayout.ItemsSource="{Binding ContactList}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Label Text="{Binding Name}" />
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </ContentPage.Content>
<StackLayout BindableLayout.ItemsSource="{Binding ContactList}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Label Text="{Binding Name}" Grid.Row="0" />
                        <Label Text="{Binding Surname}" Grid.Row="1" />
                        <Label Text="{Binding Number}" Grid.Row="2" />
                        <BoxView HeightRequest="1" BackgroundColor="#ccc"
                                 Grid.Row="3"/>
                    </Grid>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>

You can handle selected Contact object with GestureRecognizers

<Grid.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding 
                                                  Path=BindingContext.SelectContactCommand,
                                                  Source={x:Reference BindablePage}}"
                                                  CommandParameter="{Binding}"/>
                        </Grid.GestureRecognizers>

Yiğit

Xamarin Developer, Consultant & Architect. Community Leader and Director of Xamarin Türkiye

Post A Reply