I have tried to bind a list of objects to a listview
for a long time, but although it works as expected with lists where I don't need to write an itemtemplate (ObservableCollection<string>
for example), it does not work with lists where i want an itembinding
to a field of an object in a list:
MainPage.xaml.cs:
ExampleList = new ObservableCollection<ExampleItem>()
{
new ExampleItem() {Showing = "Item 1"},
new ExampleItem() {Showing = "Item 2"}
};
ListView.ItemsSource = ExampleList;
Mainpage.xaml:
<ListView x:Name="ListView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Showing}" TextColor="White"></TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Although the list items are there(!), the text in the rows just doesn't show up: Binding Result
I already tried this solution, result was the same : Xamarin ListView not displaying any data
ANSWER: It seems that binding doesn't (fully) work with fields, the variables need to be properties!
Make sure the items in the ItemsSource implement INotifyPropertyChanged and the setter of each property you are binding to triggers the PropertyChanged event.
That's besides triggering PropertyChanged on the property setter of the ItmsSource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With