New to Telerik UI for Xamarin? Download free 30-day trial

How to bind ListViewGridLayout SpanCount property of RadListView?

Environment

Product Version R2 2021
Product ListView for Xamarin

Description

Let's have the following RadListView with ListViewGridLayout configured as follow:

<telerikDataControls:RadListView x:Name="listView"
                                ItemsSource="{Binding Source}">
    <telerikDataControls:RadListView.LayoutDefinition>
        <telerikListView:ListViewGridLayout SpanCount="2"
                                            ItemLength="120"/>
    </telerikDataControls:RadListView.LayoutDefinition>
</telerikDataControls:RadListView>

The requirement is to update the SpanCount property through a binding.

Solution

The tricky part is the ListViewGridLayout does not receive the binding context of the ListView directly. The binding context should be explicitly applied like this:

<telerikDataControls:RadListView x:Name="listView"
                                ItemsSource="{Binding Source}">
    <telerikDataControls:RadListView.LayoutDefinition>
        <telerikListView:ListViewGridLayout SpanCount="{Binding BindingContext.SpanCountValue, Source={x:Reference listView}}"
                                            ItemLength="120"/>
    </telerikDataControls:RadListView.LayoutDefinition>
</telerikDataControls:RadListView>
In this article
Not finding the help you need? Improve this article