GroupHeader in Listview with bindable and static items

I have a SfListView with an ItemTemplate in it. My idea is that there must have a GroupHeader to separate some items. Let me explain:


group header

bindable item

bindable item

bindable item

bindable item

bindable item

group header

static item

static item

group header

static item

static item


I alreay fill the bindable items, but not sure how to add the GroupHeader's and the static items


    <listview:SfListView x:Name="listView" ItemsSource="{Binding MenuInfo}" AutoFitMode="Height" BackgroundColor="White">

     <listview:SfListView.ItemTemplate>

     <DataTemplate>

     <StackLayout>

     <Grid Padding="16,6,16,4">

     <Label Text="{Binding MenuTexto}" TextColor="Black" FontSize="15" />

     </Grid>


     <BoxView IsVisible="{Binding .,Converter={StaticResource separatorVisibilityConverter}, ConverterParameter={x:Reference Name=listView}}" BackgroundColor="#93abd3" HeightRequest="1"/>

     </StackLayout>

     </DataTemplate>

     </listview:SfListView.ItemTemplate>

    </listview:SfListView>


The BoxView is a line separator


I fill the listview using this (the finall version will be readed from a Webservice)


    menuInfo = new ObservableCollection<MenuInfo>();

    menuInfo.Add(new MenuInfo() { MenuTexto = "Item 1", MenuInterno = "id1" });

    menuInfo.Add(new MenuInfo() { MenuTexto = "Item 2", MenuInterno = "id2" });

    menuInfo.Add(new MenuInfo() { MenuTexto = "Item 3", MenuInterno = "id3" });








2 Replies

SU sunco October 17, 2021 11:31 PM UTC

I ended changinf the SfListview with a regular ListView


<ListView x:Name="listView" IsGroupingEnabled="true" HasUnevenRows="True" BackgroundColor="White">


                <ListView.GroupHeaderTemplate>

                    <DataTemplate>

                        <ViewCell>

                            <StackLayout BackgroundColor="#989898">

                                <Label Text="{Binding Texto}" TextColor="White" FontAttributes="Bold" Padding="10,6,10,6" />

                            </StackLayout>

                        </ViewCell>

                    </DataTemplate>

                </ListView.GroupHeaderTemplate>


                <ListView.ItemTemplate>

                    <DataTemplate>

                        <ViewCell>

                            <StackLayout>

                                <Label Text="{Binding Texto}" TextColor="#7f7f7f" Padding="10,12,10,12" />

                            </StackLayout>

                        </ViewCell>

                    </DataTemplate>

                </ListView.ItemTemplate>


            </ListView>



SY Suthi Yuvaraj Syncfusion Team October 18, 2021 12:17 PM UTC

Hi Sunco,  
 
Thank you for contacting Syncfusion support.  
 
Regarding issue “GroupHeader in Listview with bindable and static items” 
 
We have checked the reported issue in simple sample having GroupHeader in ListView with bindable items and static items outside the ListView. We would like to let you know that bindable items can only set inside the ListView and Static items is set outside the Listview. Grouping can be done by  defining the group descriptor object, and adding it into the DataSource.GroupDescriptors collection.  
 
We have attached the workable sample and documentation link for your reference 
 
 
Please let us know if you need further assistance.  
 
 
Regards,  
Suthi Yuvaraj.  


Loader.
Up arrow icon