Using GroupHeaderTemplate with BindableProperty Key inside a ContentPage with x:DataType set?

Given the contrived page structure as follows, what is the DataType required to satisfy the XAML compiler error "Error XFC0045 Binding: Property "Key" not found on "MyViewModel"?

<!-- x:DataType is set on the ContentPage for compile-time binding validations -->
<ContentPage x:DataType="{x:Type MyViewModel}">
     <SfListView ItemSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem}">
          <SfListView.DataSource>
               <DataSource>
                    <DataSource.GroupDescriptors>
                         <GroupDescriptor PropertyName="MyGroupingProperty" />
                    </DataSource.GroupDescriptors>
               </DataSource>
          </SfListView.DataSource>
          <SfListView.GroupHeaderTemplate>
                                   <!-- XAML compiler is looking for value "Key" on the ContentPage-level x:DataType attribute because x:DataType is not defined for this DataTemplate -->
               <DataTemplate x:DataType="{x:Type WHAT GOES HERE?}">
                    <Label Text="{Binding Key" />
               </DataTemplate>
          </SfListView.GroupHeaderTemplate>
     </SfListView>
</ContentPage>


5 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team March 9, 2021 07:45 AM UTC

Hi Andrew,

Thank you for contacting syncfusion support.
 
 
#Regarding How to enable compiled binding in SfListview 
We would like to inform you that we have already documented about “How to enable compiled binding in SfListview” in our Syncfusion Knowledge base. You can refer the same from the following location. 
 
 
We hope this helps. Please let us know if you need any further assistance. 
  
Regards,
SaiGanesh Sakthivel
 



AH Andrew Hoke March 9, 2021 04:19 PM UTC

Thank you, this is exactly what I needed; however, it would be really nice if all the documentation was in one place instead of scattered around multiple corners of the website. I will make sure to check this KB area in the future in addition to the API reference.


LN Lakshmi Natarajan Syncfusion Team March 10, 2021 11:01 AM UTC

Hi Andrew, 
 
Thank you for your response. 
 
We are glad that your requirement has been met at your side. 
 
#Regarding it would be really nice if all the documentation was in one place instead of scattered around multiple corners of the website 
 
You can refer to all our KB documents, platform and control specific, from the following link, 
 
In addition, we've categorized our knowledge base documents by feature and updated our user guide document, 
 
Please let us know if you need further assistance. As always we are happy to help you out. 
 
Lakshmi Natarajan 
 


Marked as answer

NB Nathen Brewer February 28, 2024 01:38 AM UTC

I had an issue with this as well. A link to this documentation within the documentation for the SfListView itself would be nice. I pushed my app to Production and users rated poorly because my group headers were missing. They were present in Debugging because I had used :

<DataTemplate x:DataType="dataSource:GroupContext">

Apparently the debugger was able to resolve this but my production build was not. 


SY Suthi Yuvaraj Syncfusion Team February 28, 2024 10:35 AM UTC

Hi Nathen Brewer,


We would like to let you know that the binding context for the GroupHeaderTemplate will be a GroupResult, we have processed the Key, DisplayItems, and counts from GroupResult in DataSource, Hence we suggest you to DataType as GroupResult. Kindly refer to the below code snippet and documentation for more reference.


Code snippet:

<syncfusion:SfListView.GroupHeaderTemplate>

<DataTemplate  x:DataType="result:GroupResult">

<StackLayout HorizontalOptions="Fill" VerticalOptions="StartAndExpand">

<Label

    FontAttributes="Bold"

    FontSize="18"

    HorizontalOptions="CenterAndExpand"

    Text="{Binding Key}"

    TextColor="White" />

</StackLayout>

</DataTemplate>

</syncfusion:SfListView.GroupHeaderTemplate>

 




UG Link: https://help.syncfusion.com/maui/listview/grouping?cs-save-lang=1&cs-lang=csharp#changing-group-header-appearance-when-expanding


Regards,

Suthi Yuvaraj.


Loader.
Up arrow icon