Xamarin.Forms Binding works, but the text does not appear

I tried to associate a list of objects with listviewfor a long time, but although it works as expected in lists where I do not need to write an itemtemplate (for example ObservableCollection<string>), it does not work with lists where I want itembindingthe object field in 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 there are elements of the list (!), The text in the lines simply does not appear: Binding Result

I already tried this solution, the result was the same: Xamarin ListView did not display any data

How can I do this job? Thanks in advance!

EDIT:

It seems that the binding does not work (completely) with fields, variables should be properties !

+4
2

, ItemsSource INotifyPropertyChanged , PropertyChanged.

PropertyChanged ItmsSource.

+1

ItemsSource ObservableCollection ListView

<ListView ItemsSource="{Binding ExampleList}">
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding Showing}" TextColor="White" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

, Xamarin.Forms MVVM. ObservableCollection ViewModel BindingContext

: ObservableCollection, , OnPropertyChange . ItemsSource.

ExampleList = new ObservableCollection<ExampleItem>();
ListView.ItemsSource = ExampleList;

ExampleList.Add(new ExampleItem() {Showing = "Item 1"});
ExampleList.Add(new ExampleItem() {Showing = "Item 2"});
0

Source: https://habr.com/ru/post/1666745/


All Articles