Cannot set color of grouped items in SfListView

Hello,

I am using SfListView in my Xamarin.Form app, where items are grouped based on Folder name.

Unfortunately I am not able to change label color.


Please see attached xaml code.


<xForms:SfListView x:Name="ListView" ItemSize="100" ItemsSource="{Binding Devices}" AllowGroupExpandCollapse="True" SelectionMode="None" SelectionGesture="Hold" SelectionBackgroundColor="{StaticResource ColorTransparent}" HoldCommand="{Binding HoldCommand}">

<xForms:SfListView.ItemTemplate>

<DataTemplate x:DataType="model:DashboardDevice">

<Grid Padding="10">

<Frame CornerRadius="10"

       BorderColor="{Binding Color}"

       BackgroundColor="{Binding Color}"

       Padding="0">

<Label Text="{Binding Name}" FontAttributes="Bold" TextColor="{StaticResource ColorText}" FontSize="19" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>

</Frame>

</Grid>

</DataTemplate>

</xForms:SfListView.ItemTemplate>

<xForms:SfListView.LayoutManager>

<xForms:GridLayout SpanCount="3"/>

</xForms:SfListView.LayoutManager>

<xForms:SfListView.DataSource>

<dataSource:DataSource>

<dataSource:DataSource.SortDescriptors>

<dataSource:SortDescriptor PropertyName="Name" Direction="Ascending"/>

</dataSource:DataSource.SortDescriptors>

<dataSource:DataSource.GroupDescriptors>

<dataSource:GroupDescriptor PropertyName="Folder"/>

</dataSource:DataSource.GroupDescriptors>

</dataSource:DataSource>

</xForms:SfListView.DataSource>

</xForms:SfListView>


I have tried to add following element but it cause that no Group label is shown.

<xForms:SfListView.GroupHeaderTemplate>

<DataTemplate x:DataType="model:DashboardDevice">

<Label x:Name="label" Text="{Binding Key}" TextColor="{StaticResource ColorText}" FontSize="20" Padding="10,10,0,0" />

</DataTemplate>

</xForms:SfListView.GroupHeaderTemplate>


Tnanks for help,

Tomas


3 Replies 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team October 14, 2021 04:53 AM UTC

Hi Martin, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Cannot set color of grouped items in SfListView” from our side. We would like to inform you that the BindingContext for the GroupHeaderTemplate will be the GroupResult. So we suggest you to set the GroupHeaderTemplate’s DataType to GroupResult. 
 
Please refer to the following code snippets to overcome the reported scenario, 
 
<ContentPage xmlns:result="clr-namespace:Syncfusion.DataSource.Extensions;assembly=Syncfusion.DataSource.Portable"> 
 
<syncfusion:SfListView.GroupHeaderTemplate> 
    <DataTemplate x:DataType="result:GroupResult"> 
        <Label x:Name="label" Text="{Binding Key}" TextColor="{StaticResource ColorText}" FontSize="20" Padding="10,10,0,0" /> 
    </DataTemplate> 
</syncfusion:SfListView.GroupHeaderTemplate> 
 
</ContentPage> 
 
 
You can also refer to our online documentation regarding the same from the following link, 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 
 


Marked as answer

MA Martin ARION October 19, 2021 06:43 PM UTC

Thanks a lot for help.

Tomas



LN Lakshmi Natarajan Syncfusion Team October 20, 2021 06:53 AM UTC

Hi Tomas, 
 
Thank you for the update. 
 
We are glad that your requirement has been met at your side. Please let us know if you need further assistance. As always, we are happy to help you out. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon