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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Group-Label is empty

Thread ID:

Created:

Updated:

Platform:

Replies:

143176 Mar 7,2019 01:33 PM UTC Mar 8,2019 07:17 AM UTC Xamarin.Forms 1
loading
Tags: SfListView
Eugen Dolgi
Asked On March 7, 2019 01:33 PM UTC

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;



Deivaselvan Y [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon