Hi, as said in the title, I have a listview filled with Contacts that i ordered in groups with grouping, I binded GroupDisplayBinding with the Key of each group.
Like that I have a list of contacts with a header showing key corresponding to the group of contacts like here :
motzcod.es/post/94643411707/enhancing-xamarin-forms-listview-with-grouping-headers
I made a custom header for this GroupHeaderTemplate:
public class HeaderCell : ViewCell
{
public HeaderCell()
{
var title = new Label()
{
Font = Font.BoldSystemFontOfSize(NamedSize.Small),
TextColor = Color.Black,
VerticalOptions = LayoutOptions.Center
};
title.SetBinding(Label.TextProperty, "Key");
View = new StackLayout
{
HorizontalOptions = LayoutOptions.Fill,
HeightRequest = 25,
BackgroundColor = Color.FromRgb(52, 152, 218),
Padding = 5,
Orientation = StackOrientation.Horizontal,
};
}
}
and linked it to my listview:
var contacts = new ListView();
content.Children.Add(contacts);
contacts.SetBinding(ListView.ItemsSourceProperty, new Binding("ContactsGrouped"));
contacts.IsGroupingEnabled = true;
contacts.GroupDisplayBinding = new Binding("Key");
contacts.GroupShortNameBinding = new Binding("Key");
contacts.SetValue(Grid.RowProperty, 1);
contacts.SetValue(Grid.ColumnProperty, 0);
contacts.HorizontalOptions = LayoutOptions.FillAndExpand;
contacts.RowHeight = 80;
contacts.ItemTemplate = new DataTemplate(typeof(ContactCell));
if (Device.OS != TargetPlatform.WinPhone)
contacts.GroupHeaderTemplate = new DataTemplate(typeof(HeaderCell));
contacts.HasUnevenRows = true;
My problem is that if I use a DataTemplate for my GroupHeaderTemplate, I got ArgumentOutOfRangeException when I scroll down my list even if all code in my DataTemplate is commented, but if let the default template, it works.
I don't know if that's a problem with Xamarin or if there's really something with my code so if someone already had this problem or knows something about this issue please tell me.
I found out that some people had the same problem in this thread but no real solution was given :
forums.xamarin.com/discussion/19714/listview-for-android-crashing-on-scroll-when-populated-with-custom-fontawesome-label