I was checking out how to use the new C# Markup functionality in my Xamarin.Forms app and I tried to implement it in a list.
However upon checking the documentation, I couldn't find an example on how to implement it. So I tried it like this:
Page code, viewModel.Init()
just gets the data for technologies:
protected override void OnAppearing() { base.OnAppearing(); viewModel.Init(); Content = new CollectionView { BackgroundColor = Color.Purple, ItemTemplate = new DataTemplate(typeof(TechCardView)) }.Bind(ItemsView.ItemsSourceProperty, nameof(viewModel.Technologies)); }
ViewModel code just in case:
public override void Init() { _ = GetStockTechnologies(); } private async Task GetStockTechnologies() { Technologies = await _getTechnologies.BuildUseCaseTaskAsync(null); }
I thought this would work because Technologies is a IEnumerable
of TechObject
, and inside TechCardView
I have only one property that is of type TechObject
, but I couldn't find a way to do a {Binding .}
inside DataTemplate like I would in XAML.
This is what I could get with the documentation in C# Markup and the DataTemplate documentation and while I do get data, the list does not show any items.
What's the proper way to do this?