I'm trying to bind a List in my ViewModel to a ListView in my Page but I can't get it to work, the ItemsSource is always null allthough the list is populated with values.
This is how I set the whole thing up.
theese attributes are added to the page tag in my xaml
xmlns:viewmodels ="using:TimeMachine3.ViewModels"
d:DataContext="{d:DesignInstance viewmodels:MasterViewModel}"
My LisstView is defined as
<ListView x:Name="lstMainMaster" ItemsSource="{Binding MyList}" SelectionChanged="lstMainMaster_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{x:Bind Name}"/>
<TextBlock Text="{x:Bind Number}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In my master.cs (the page code) I have
private ViewModels.MasterViewModel viewmodel;
//constructor
public master()
{
this.InitializeComponent();
this.Loaded += Master_Loaded;
}
private void Master_Loaded(object sender, RoutedEventArgs e)
{
viewmodel = new ViewModels.MasterViewModel();
viewmodel.populate();
}
And in masterViewmodel (the viewmodel of the page) I have this code
private ObservableCollection<Month> _myList;
public ObservableCollection<Month> MyList{ get {return _myList; } }
public void Populate()
{
_myList = new ObservableCollection<Month>(DataBase.GetMonths(2017));
}