GroupHeaderTemplate for blank values

2 posts, 1 answers
  1. Simon
    Simon avatar
    13 posts
    Member since:
    Mar 2020

    Posted 28 Apr 2020 Link to this post

    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?
  2. Answer
    Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1195 posts

    Posted 28 Apr 2020 Link to this post

    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.
Back to Top