public class SfListViewBehavior : Behavior<SfListView>
{
SfListView ListView;
protected override void OnAttachedTo(SfListView bindable)
{
ListView = bindable;
ListView.DataSource.GroupDescriptors.Add(new Syncfusion.DataSource.GroupDescriptor()
{
PropertyName = "GroupText"
});
ListView.PropertyChanged += ListView_PropertyChanged;
base.OnAttachedTo(bindable);
}
private void ListView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "ItemsSource")
{
ListView.DataSource.GroupDescriptors.Clear();
ListView.DataSource.GroupDescriptors.Add(new Syncfusion.DataSource.GroupDescriptor()
{
PropertyName = "GroupText"
});
}
}
} |
<ScrollView Orientation="Vertical">
<ContentView>
<ContentView.Triggers>
<DataTrigger TargetType="ContentView" Binding="{Binding IsAlphabets}" Value="True">
<Setter Property="Content">
<Setter.Value>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1500"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<syncfusion:SfListView x:Name="alphabetList"
ItemsSource="{Binding Alphabets}"
ItemSize="112" ItemSpacing="20" VerticalOptions="FillAndExpand">
<syncfusion:SfListView.Behaviors>
<behavior:SfListViewBehavior/>
</syncfusion:SfListView.Behaviors>
<syncfusion:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding Key}"/>
</DataTemplate>
</syncfusion:SfListView.GroupHeaderTemplate>
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ItemText}"/>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
<Grid Grid.Row="1" BackgroundColor="Green">
</Grid>
</Grid>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger TargetType="ContentView" Binding="{Binding IsAlphabets}" Value="False">
<Setter Property="Content">
<Setter.Value>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1500"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<syncfusion:SfListView x:Name="numbersList"
ItemsSource="{Binding Numbers}"
ItemSize="112" ItemSpacing="20" VerticalOptions="FillAndExpand">
<syncfusion:SfListView.Behaviors>
<behavior:SfListViewBehavior/>
</syncfusion:SfListView.Behaviors>
<syncfusion:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding Key}"/>
</DataTemplate>
</syncfusion:SfListView.GroupHeaderTemplate>
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ItemText}"/>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
<Grid Grid.Row="1" BackgroundColor="Red">
</Grid>
</Grid>
</Setter.Value>
</Setter>
</DataTrigger>
</ContentView.Triggers>
...
</ContentView>
</ScrollView> |