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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

142440 Feb 4,2019 09:00 PM UTC Feb 6,2019 06:24 AM UTC Xamarin.Forms 3
loading
Tags: SfListView
Jeffrey
Asked On February 4, 2019 09:00 PM UTC

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!

Jayaleshwari N [Syncfusion]
Replied On 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. 
  
<syncfusion:SfListView>  
          <syncfusion:SfListView.GroupHeaderTemplate>  
                    <DataTemplate>  
                        <ViewCell>  
                            <ViewCell.View>  
                                <StackLayout BackgroundColor="{Binding .,Converter={StaticResourceTemplateConverter}}"  
                                             Padding="{Binding Level,Converter={StaticResource TemplateConverter}}">  
                                    <Label Text="{Binding Key}" />  
                                </StackLayout>  
                            </ViewCell.View>  
                        </ViewCell>  
                    </DataTemplate>  
                </syncfusion:SfListView.GroupHeaderTemplate>  
</syncfusion:SfListView>  
  
  
 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");  
                    else  
                        return Color.AliceBlue;  
                }  
                else  
                {  
                    if ((int)groupResult.Level == 1)  
                        return new Thickness(5, 5, 5, 0);  
                    else  
                        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.  
  
Regards,  
Jayaleshwari N 


Jeffrey
Replied On February 5, 2019 04:28 PM UTC

Exactly what I needed!

Thank you all for your incredible controls and support!

Jayaleshwari N [Syncfusion]
Replied On February 6, 2019 06:24 AM UTC

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


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

;