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

GroupHeaderTemplate is created twice for single group

4 Answers 93 Views
ListView
This is a migrated thread and some comments may be shown as answers.
VincentH
Top achievements
Rank 1
VincentH asked on 28 Oct 2016, 08:52 AM

Hi,

I am trying to create the equivalent of a header template in the RadListView by using grouping with a single group.

The problem is that the group header template is invoked twice instead of once, resulting in 2 headers displayed on top of each other with a slight offset. Am I doing something wrong or is this a bug in RadListView?

Here are my relevant code snippets:

list.GroupHeaderTemplate = new DataTemplate(() => {
    return new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" }; // This is invoked twice instead of once
});

list.GroupDescriptors.Add(new PropertyGroupDescriptor { PropertyName = nameof(TestItem.GroupKey) });

Where the ItemsSource is a List<TestItem> with 50 items and the TestItem class is defined as:

    class TestItem
    {
        static object groupKey = new object();
        public object GroupKey { get { return groupKey; } }
    }


4 Answers, 1 is accepted

Sort by
0
VincentH
Top achievements
Rank 1
answered on 31 Oct 2016, 07:51 AM

PS When I create a single header instance and return that each time in the GroupHeaderTemplate (see code below), the header looks OK but I still wonder whether this invoke twice behaviour is by design or a bug?

var header = new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" };
GroupHeaderTemplate = new DataTemplate(() => {
  return header; // This is called twice instead of once so do not create new view instances here
});

0
Pavel R. Pavlov
Telerik team
answered on 01 Nov 2016, 10:58 AM
Hello Vincent,

I tried to reproduce the issue on our side and it seems that the code works as expected. I tested this scenario with the following code:

    public StartPage()
    {
        InitializeComponent();
        var list = new RadListView();
        list.ItemsSource = this.GenerateSource();
        list.GroupDescriptors.Add(new PropertyGroupDescriptor() { PropertyName = "Day" });
        list.ItemTemplate = new DataTemplate(() =>
        {
            return new ListViewTemplateCell()
            {
                View = CreateView()
            };
        });
        list.GroupHeaderTemplate = new DataTemplate(() =>
        {
            return new Label()
            {
                HorizontalTextAlignment = TextAlignment.Center,
                Text = "Welcome to Xamarin Forms!"
            };
        });
        Content = list;
    }
    private View CreateView()
    {
        var b = new Binding() { Path = "Content" };
        var l = new Label();
        l.SetBinding(Label.TextProperty, b);
        var g = new Grid();
        g.Children.Add(l);
        return g;
    }
    private System.Collections.IEnumerable GenerateSource()
    {
        var results = new List<Event>();
        results.Add(new Event() { Content = "You are now free to do whathever", Day = "Today" });
        results.Add(new Event() { Content = "Content of the item", Day = "Today" });
        results.Add(new Event() { Content = "This also happens today", Day = "Today" });
        results.Add(new Event() { Content = "More events today", Day = "Today" });
        results.Add(new Event() { Content = "Go shopping after 19:00", Day = "Today" });
        return results;
    }
}
internal class Event
{
    public string Content { get; set; }
    public string Day { get; set; }
}
Could you please share more information about your setup? Which version of the controls you use? Is your setup different in any way? Could you please try to reproduce the reported behavior in a small repro project and send it over.  It will allow us to further investigate the reasons behind.

Regards,
Pavel R. Pavlov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 05 Jul 2020, 03:55 PM

Hello, also i faced this issue this month. Is there any update for this issue? GroupHeaderTemplate is created twice for single group.

0
Yana
Telerik team
answered on 06 Jul 2020, 08:26 AM

Hi Gökhan,

I would need more details on the scenario you have at hand, as we are not aware of such an issue with RadListView GroupHeaderTemplate.

Please send me the ListView definition as well as the used ViewModel/code-behind, so I can try to recreate the setup on my side. 

In addition, now RadListView provides HeaderTemplate, you can learn more about this here:  ListView Header and Footer 

I look forward to your reply.

Regards,
Yana
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
VincentH
Top achievements
Rank 1
Answers by
VincentH
Top achievements
Rank 1
Pavel R. Pavlov
Telerik team
n/a
Top achievements
Rank 1
Yana
Telerik team
Share this question
or