We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Group-Label is empty

In this very simple example, the bound group names are not displayed (property Address is definitely not empty). Static texts are displayed. What am I doing wrong?

        <listView:SfListView x:Name="listView"  ItemsSource="{Binding Appointments}" 
                         Margin="0" Padding="0,2,0,2" ItemSpacing="3,1,3,1" ItemSize="50" 
                         BackgroundColor="#fff" SelectionBackgroundColor="#ECECEC"
     FocusBorderThickness="0" AllowGroupExpandCollapse="True" GroupHeaderSize="30">

            <listView:SfListView.DataSource>
                <dataSource:DataSource>
                    <dataSource:DataSource.SortDescriptors>
                        <dataSource:SortDescriptor PropertyName="Date" Direction="Ascending"/>
                    </dataSource:DataSource.SortDescriptors>
                    <dataSource:DataSource.GroupDescriptors>
                        <dataSource:GroupDescriptor PropertyName="Address"/>
                    </dataSource:DataSource.GroupDescriptors>
                </dataSource:DataSource>
            </listView:SfListView.DataSource>

            <listView:SfListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Horizontal" BackgroundColor="#ddd">
                                <!--<Label Text="Boo" TextColor="SteelBlue" FontSize="16"  FontAttributes="Bold" VerticalOptions="Center"/>-->
                                <Label Text="{Binding Address}" TextColor="SteelBlue"  FontSize="16"  FontAttributes="Bold" VerticalOptions="Center"  />
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </listView:SfListView.GroupHeaderTemplate>


    public class Appointment
    {
        public string UserName { get; set; } = string.Empty;
        public string Address { get; set; } = string.Empty;
        public DateTime Date { get; set; } = DateTime.MinValue;



1 Reply

DY Deivaselvan Y Syncfusion Team March 8, 2019 07:17 AM UTC

Hi Eugen, 
 
Thanks for using Syncfusion products. 
 
We have checked the reported query from our side. You cannot bind the Model property directly into the group header template because group header template will have GroupResult as its BindingContext. So, you can only bind property like Count, Items, Level, Key to group header template. If you want to display any model property, then you can use KeySelector like below. We have attached the tested sample for your reference, please find the sample from following. 
 
 
To know more about grouping, please refer our documentation link below. 
 
 
<syncfusion:SfListView> 
    <syncfusion:SfListView.GroupHeaderTemplate> 
        <DataTemplate> 
            <ViewCell> 
                <ViewCell.View> 
                   <StackLayout Orientation="Horizontal" BackgroundColor="#ddd"> 
                       <Label Text="{Binding Key}" TextColor="SteelBlue"  FontSize="16"  FontAttributes="Bold" VerticalOptions="Center"  /> 
                  </StackLayout> 
               </ViewCell.View> 
            </ViewCell> 
        </DataTemplate> 
   </syncfusion:SfListView.GroupHeaderTemplate> 
</syncfusion:SfListView> 
 
 
Customize KeySelector value like below. 
 
 
public partial class MainPage : ContentPage 
{ 
     public MainPage() 
     { 
        listView.DataSource.GroupDescriptors.Add(new GroupDescriptor() 
        { 
           PropertyName = "ContactName", 
           KeySelector = (object obj1) => 
           { 
              var item = (obj1 as Contacts); 
              return item.ContactName; 
            } 
        }); 
      } 
} 
 
 
Please let us know if this sample helps you to achieve your requirement. 
 
Regards, 
Deivaselvan 


Loader.
Live Chat Icon For mobile
Up arrow icon