IsStickyGroupHeader Not Working As Expected

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

7 Replies

JN Jayaleshwari N Syncfusion Team August 15, 2018 02:11 PM UTC

  
Thanks for contacting Syncfusion support.  
  
Query 1:   
  
Please find the API reference link from the below link.  
  
  
Query 2:   
  
We have checked the reported query from our end. We have prepared the sample based on the information given by you. Unfortunately, the reported issue does not replicate at our end. Group header is loaded in the view as expected.  
    
For your reference we have attached the sample and you can download it from the below link.    
    
    
Can you please check whether the reported issue occurs in our sample also? If possible, can you please modify our sample to replicate the reported issue in our sample and share the replication procedure which would highly help us to analyze the query better.        
  
Regards,  
Jayaleshwari N.


PP Paul Parkins August 22, 2018 01:07 PM UTC

Hi.
Thanks for the link to the docs, and for the sample project. Although the link you provided includes everything in the ListView.XForms namespace, it still does not list all the SfListView members. However for other interested readers, I found what I needed here

I can confirm that your project worked as expected. I have spent some time attempting to break your project as well as attempting to un-break my own.

It seems to me that this issue I am seeing is to do with when I populate my data items within the data model in relation to when the behaviour is attached the the Listview. My project using FreshMVVM and as such my page model inherits from a base class FreshMvvm.FreshBagePageModel which adds a few methods such as ViewIsAppearing and ViewIsDisappearing. I was loading my data with ViewIsAppearing so that it always had the latest data whenever the view was displayed (as opposed to when the view model was created). It would seems that when the behaviour's OnAttachedTo event is triggered, the ListView's ItemsSource property is null.

When I populate my data within the view model's constructor, then the sticky group header works as expected. So it would seem that although everything else about the list works ok, if the grouping behaviour is attached to the ListView before the ListView has some ItemsData, then the very first group header does not work if a sticky header is enabled.

So it seems to me that I could either a) Make do with a non-sticky group header b) Re-order my data loading so it is performed before the behaviour is attached to the view c) Have the listview/behaviour refresh themselves after the data has been loaded in IsViewAppearing (calling SfListView.RefreshView does not seem to help).

As I am avoiding "code behind" as much as possible, I don't really have control of when the behaviour is created or attached to the listview. So I think option (b) is likely the route to go with. Would you have any other suggestions?

Thanks

Paul









DY Deivaselvan Y Syncfusion Team August 24, 2018 12:54 PM UTC

Hi Paul,

We can reproduce the reported issue with the given details. We have logged a defect report for this. The fix for this issue will be included in our upcoming 2018 Volume 3 release which will be expected to be available by end of September 2018. We will appreciate your patience until then.  

Regards,
Deivaselvan 



JN Jayaleshwari N Syncfusion Team September 14, 2018 12:31 PM UTC

Hi Paul, 
We are glad to announce that our Essential Studio 2018 Volume 3 beta Release v16.3.0.17 is rolled out and is available for download under the following link.  
  
   
The reported issue The sticky group header is not updating properly while navigating between the pages in Android and iOS platforms” has been resolved and included in this release .We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.  
  
Regards,  
Jayaleshwari N. 



PP Paul Parkins September 14, 2018 01:13 PM UTC

Huh? A software company that delivers on schedule as promised? - Does not compute!   ;)

Thank you for the timely update, and the heads up. I can confirm that this issue appears to have been fixed in this release.


JN Jayaleshwari N Syncfusion Team September 17, 2018 11:55 AM UTC

Hi Paul, 
 
Thanks for the update.  
Please get in touch if you would require any further assistance. 
 
Regards, 
Jayaleshwari N. 



JN Jayaleshwari N Syncfusion Team September 24, 2018 05:50 AM UTC

Hi Paul,       
We are glad to announce that our Essential Studio 2018 Volume 3 Main Release v16.3.0.21 is rolled out and is available for download under the following link.     
The reported issue “The sticky group header is not updated properly while navigating between the pages in Android and iOS platforms.” has been resolved and included in this release .We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.     
 
Regards, 
Jayaleshwari N. 


Loader.
Up arrow icon