I implemented datasource on xamarin.forms listview as below. It works fine on Android but it doesnt work on UWP only group headers are displayed but not items.
I have checked your SampleBrowser-Forms application and there you have implemented a customlistview on UWP using CustomRenderer. Not sure if existing listview doesnt work on UWP or not.
listview.ItemTemplate = new DataTemplate(() =>
{
var label = new ExtendedLabel()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(10, 0),
TextColor = Color.Black,
FontSize = 12,
VerticalTextAlignment = TextAlignment.Start,
BackgroundColor = Color.White,
LineBreakMode = LineBreakMode.WordWrap
};
label.SetBinding(Label.TextProperty, new Binding("Name", BindingMode.Default,new Convertors.HtmltoTextConvertor(), null));
var viewCell = new ViewCell() { View = label };
viewCell.BindingContextChanged += ViewCell_BindingContextChanged;
return viewCell;
});
dataSource.EndInit();
listview.ItemsSource = dataSource.DisplayItems;
private DataSource setDetails()
{
DataSource dataSource = new DataSource();
dataSource.Source = ViewModel.Details;
dataSource.GroupDescriptors.Add(new GroupDescriptor("Title")
{
PropertyName = "Title",
KeySelector = (object obj1) =>
{
var item = (obj1 as Models.Detail);
return item.Title.ToString();
}
});
return dataSource;
}
private void ViewCell_BindingContextChanged(object sender, EventArgs e)
{
try
{
ViewCell viewCell = sender as ViewCell;
if ((viewCell.BindingContext is Models.Detail)==false)
{
var label = new Label()
{
TextColor = Color.Black,
FontSize = 14,
HeightRequest = 30,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
BackgroundColor = Color.Gray
};
label.SetBinding(Label.TextProperty, new Binding("Key"));
viewCell.View = label;
}
}
catch (Exception)
{
}
}