I've got the following listview.
var headerTemplate = new DataTemplate(typeof (ModuleMediaListHeaderTemplate));
headerTemplate.CreateContent();
var itemTemplate = new DataTemplate(typeof (ModuleMediaListItemTemplate));
itemTemplate.CreateContent();
_listView = new ListView
{
IsGroupingEnabled = true,
HasUnevenRows = false,
GroupHeaderTemplate = headerTemplate,
ItemTemplate = itemTemplate
};
_listView.SetBinding(ListView.ItemsSourceProperty, "MediaSections");
_listView.ItemSelected += async (sender, args) => await TriggerMedia((MediaViewModel) args.SelectedItem);
my ModuleMediaListHeaderTemplate is super simple
public class ModuleMediaListHeaderTemplate : ViewCell
{
public ModuleMediaListHeaderTemplate()
{
var title = new Label { TextColor = Color.White, YAlign = TextAlignment.Center };
title.SetBinding(Label.TextProperty, new Binding("Key", BindingMode.Default, new UppercaseValueConverter()));
View = new StackLayout
{
Padding = new Thickness(8, 0),
BackgroundColor = Color.FromHex(Colors.br_dark_royal_blue),
Orientation = StackOrientation.Horizontal,
Children = { title },
};
}
}
And my ViewModel is responsible for taking an IGrouping list and converting it to an ObservableCollection.
public ObservableCollection<IGrouping<string, MediaViewModel>> MediaSections { get; set; }
public IList<MediaViewModel> Media
{
set
{
MediaSections = value.OrderBy(o => o.Number)
.GroupBy(x => x.ModuleSection.Name)
.ToObservableCollection();
OnPropertyChanged();
OnPropertyChanged(() => MediaSections);
}
}
ToObservableCollection is a simple extension method
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> collection)
{
return collection != null ? new ObservableCollection<T>(collection) : null;
}
My problem is that when I run in DEBUG mode, the Header Binding works properly, HOWEVER, when in Release mode, it cannot find the property "Key" for this binding
title.SetBinding(Label.TextProperty, new Binding("Key", BindingMode.Default, new UppercaseValueConverter()));
is this the nature of converting an IGrouping to an ObservableCollection, or is this a bug?