I’m having trouble getting a listview to bind to a ViewModel. The code for my ViewModel is as follows:
class MyViewModel : INotifyPropertyChanged
{
ObservableCollection<MyDataItemViewModel> dataToShow;
public ObservableCollection<MyDataItemViewModel> DataToShow
{
get
{
return dataToShow; // A breakpoint here is never hit
}
}
public MyViewModel(ObservableCollection<MyDataItemViewModel> toShow)
{
dataToShow = toShow; // A breakpoint here reveals that there is data
RegisterCommands();
}
...
My XAML is as follows:
<ListView Name="DataView"
...
ItemsSource="{Binding MyViewModel.DataToShow}">
<ListView.View>
<GridView>
<GridViewColumn Header="Number"
...
DisplayMemberBinding="{Binding Path=Details.Number}" />
...
The code for the MyDataItemViewModel class returns a public class called Details, which contains a number of properties, including Number.
The screen displays fine, but without any data.
Try this: