Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms Binding works, but text is not showing

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!

like image 309
VisualManuel Avatar asked Jan 13 '17 18:01

VisualManuel


1 Answers

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.

like image 114
Striver Avatar answered Oct 11 '22 22:10

Striver