This is a migrated thread and some comments may be shown as answers.

GroupHeaderTemplate for blank values

1 Answer 47 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Veteran
Simon asked on 28 Apr 2020, 09:56 AM
This isnt necessarily just blank values but I am trying to style the group template based on the value being grouped on. I have a custom GroupHeaderTemplate and GroupHeaderStyle set and have tried converters but it never seems to be fired. is this the right path or is there another way of hiding the groupby header or using a different template based on the vale being grouped?

1 Answer, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 28 Apr 2020, 07:40 PM

Hello Simon,

The BindingContext of the GroupHeaderTemplate gives you everything you need for that group. Please visit the RadListView GroupHeaderTemplate tutorial for a list of all the properties of the context.

You can use an IValueConverter or DataTriggers in there if you want to do different things based on the group's values.

For example , let's say you wanted to change the text color based on what the group's Key is

public class MyGroupHeaderTextColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        // The BindingContext of your DataTemplate is GroupHeaderContext
        if (value is Telerik.XamarinForms.DataControls.ListView.GroupHeaderContext context)
        {
            var headerText = context.Key.ToString();

            switch (headerText)
            {
                case "Dairy":
                    return Color.Gold;
                case "Bakery":
                    return Color.SandyBrown;
                case "Meats":
                    return Color.IndianRed;
            }

            // other properties of the context that you can use

            // context.IsExpanded
            // context.Items
            // context.Level
        }

        return Color.Black;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

You use that converter like any converter:

 

If you're trying to hide the header entirely, you could try making the height smaller and not have any elements in there, but that will not completely make it go away because the group header is a fundamental part of the infrastructure.

Regards,
Lance | Team Lead - US DevTools Support
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ListView
Asked by
Simon
Top achievements
Rank 1
Veteran
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or