Hi,
Firstly a quick question - where can I find the documentation on all SfListView members (properties, methods, events)? I would have expected it somewhere in the SfListview documentation, but I can't find it anywhere within
this tree of categories
I have been implementing SfListView grouping using Xamarin Forms v3.1.0.697729 and SfListView v16.2.0.46 , based on the supplied example project. What I find is that if I have IsStickyGroupHeader set to false, then it appears to be working as I expect. But if I set it to true, then the group header for the very first item does not appear (there is a space where it should be, the space is not coloured as per group headers, and the header contain no content).
This is my SfListView definition in xaml
<syncListView:SfListView x:Name ="MachinesListView"
ItemsSource="{Binding Machines}"
SelectedItem="{Binding SelectedMachine, Mode=TwoWay}"
ItemSize="70"
SelectionBackgroundColor="{StaticResource playsafe_green}"
FocusBorderThickness="0"
IsStickyGroupHeader="True"
AllowGroupExpandCollapse="True"
GroupHeaderSize="40">
<syncListView:SfListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal" BackgroundColor="#E4E4E4">
<Label Text="{Binding Key}" FontSize="22" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Start" Margin="20,0,0,0" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</syncListView:SfListView.GroupHeaderTemplate>
<syncListView:SfListView.Behaviors>
<behaviours:SelectMachineListViewBehaviour Machines="ItemsSource"/>
</syncListView:SfListView.Behaviors>
<syncListView:SfListView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding MachineName}" FontSize="Medium" FontAttributes="Bold" Grid.ColumnSpan="2"/>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding MachineRef}" FontSize="Small"/>
<StackLayout Grid.Row="1" Grid.Column="1" Margin="0" Spacing="0" Padding="0" Orientation="Horizontal" IsVisible="{Binding BindingContext.LocationsVisible, Source={x:Reference SelectionStack}}" >
<Label Text="Location" FontSize="Small" HorizontalOptions="End" HorizontalTextAlignment="Start" />
<Label Text="{Binding Location}" FontSize="Small" HorizontalOptions="EndAndExpand" HorizontalTextAlignment="End" />
</StackLayout>
</Grid>
</DataTemplate>
</syncListView:SfListView.ItemTemplate>
</syncListView:SfListView>
This is my behaviour
[Preserve(AllMembers = true)]
class SelectMachineListViewBehaviour : Behavior<SfListView>
{
private Syncfusion.ListView.XForms.SfListView _ListView; // The list view we are attached to
public static readonly BindableProperty MachinesProperty = BindableProperty.CreateAttached("Machines", typeof(IEnumerable<Machine>), typeof(SelectMachineListViewBehaviour), null);
// This property present so we can use the Machines data from the view model
// See https://stackoverflow.com/questions/42238500/pass-parameter-into-xamarin-forms-behaviour
public IEnumerable<Machine> Machines
{
get => (IEnumerable<Machine>)GetValue(MachinesProperty);
set => SetValue(MachinesProperty, value);
}
protected override void OnAttachedTo(SfListView listView)
{
_ListView = listView;
_ListView.DataSource.SortDescriptors.Add(new SortDescriptor("MachineName"));
_ListView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
{
PropertyName = "MachineName",
KeySelector = (object obj) =>
{
var item = (obj as Machine);
return item.MachineName[0].ToString();
}
});
base.OnAttachedTo(listView);
}
protected override void OnDetachingFrom(SfListView listView)
{
_ListView = null;
base.OnDetachingFrom(listView);
}
}
As I mentioned it is based on the listview grouping sample project. One difference is that I did not want my behaviour to create it's own ItemsSource since I already have the data in my view model. Therefore I defined the listview's ItemsSource in xaml to point to the view model's data, and then pass this as a parameter to the behaviour
<syncListView:SfListView.Behaviors>
<behaviours:SelectMachineListViewBehaviour Machines="ItemsSource"/>
</syncListView:SfListView.Behaviors>
As I said, it works, it just doesn't display the first group if I want to make the group sticky.
Any ideas why?
Thanks
Paul