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

Different Colored GroupHeader's based on "Level" and "Items"

I have a sfListView that is grouped into 2 levels.
I have 2 GroupDescriptors defined

            lstView.DataSource.GroupDescriptors.Add(new GroupDescriptor() { PropertyName = "CurrentPositionWithName" });
            lstView.DataSource.GroupDescriptors.Add(new GroupDescriptor() { PropertyName = "Description" });

I have a GroupHeaderTemplate that uses a grid to make the background a specific color for each GroupHeader.  I am using a Converter to return the correct color.

My problem is depending on the "Level", I return a different color based on the underlying list of items.

It seems that the binding only lets you bind to things like "Level", "Items" etc.  I can pass one or the other, but not both.

Is there a way to get/pass both the "Level" and the "Items" to the Converter? 

HOPE this makes sense.

BTW, I am doing all of this in C# and no xaml!

3 Replies

JN Jayaleshwari N Syncfusion Team February 5, 2019 12:14 PM UTC

Hi Jeffery,  
Thanks for contacting Syncfusion Support.  
We have checked the reported query “Different Colored GroupHeader's based on "Level" and "Items"” from our side. We would like to let you know that you can bind label with `.`(dot) to pass its binding context `GroupResult` as the value to Converter. In group header template, GroupResult will be its BindingContext. So, when you bind `. ` , converter of the label will pass GroupResult as its value which contains Items, Count, Key, level. Therefore, you can access both Items and Level in converter. 
                                <StackLayout BackgroundColor="{Binding .,Converter={StaticResourceTemplateConverter}}"  
                                             Padding="{Binding Level,Converter={StaticResource TemplateConverter}}">  
                                    <Label Text="{Binding Key}" />  
 Code snippet C#: Converter to get key, level, Items in GroupResult 
public class GroupHeaderConverter : IValueConverter  
   public object Convert(object value, Type targetType, object parameter, CultureInfo culture)  
            if (value == null)  
                return value;  
           var groupResult = value as GroupResult;  
           if (groupResult == null)  
                return value;  
               if (targetType.Name == "Color")  
                    if ((int)groupResult.Level == 1 && (int)groupResult.Count > 1)  
                        return Color.FromHex("#D3D3D3");  
                        return Color.AliceBlue;  
                    if ((int)groupResult.Level == 1)  
                        return new Thickness(5, 5, 5, 0);  
                        return new Thickness((int)value * 15, 5, 5, 0);  
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)  
         throw new NotImplementedException();  
We have attached the tested sample for your reference and you can download the same from the following location.  
Please let us know if you would require any further assistance.  
Jayaleshwari N 

JE Jeffrey February 5, 2019 04:28 PM UTC

Exactly what I needed!

Thank you all for your incredible controls and support!

JN Jayaleshwari N Syncfusion Team February 6, 2019 06:24 AM UTC

Hi Jeffery, 
Thanks for the update. Please get in touch if you would require further assistance. 
Jayaleshwari N. 

Live Chat Icon For mobile
Up arrow icon