I am using the Microsoft.Toolkit.Mvvm library as an MVVM library. My C# code is the following:
class SampleViewModel : ObservableObject
{
private List<int> _sampleList;
public List<int> sampleList
{
get => _sampleList;
set
{
SetProperty(ref _sampleList, value);
}
}
}
The XAML code I am attempting to use to display all the values of the List<int>
is:
<ListView x:Name="mylistview" ItemsSource="{x:Bind ViewModel.sampleList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:Int32">
<TextBlock Text="{x:Bind}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
When the list is updated, the elements are created, but the value of the int is not displayed, only an empty row is present. If I use the following, I can display the value:
<TextBlock Text="{x:Bind ViewModel.sampleList[0], Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
How should I change the ListView, so that it displays the values as well?