I have this XAML:
<ListBox x:Name="MyItemsList" ItemsSource="{Binding MyItems}" SelectionChanged="ItemsList_SelectionChanged">
The code behind assigns the datacontext of the view model page:
DataContext = App.ViewModel;
My ViewModel object defines MyItems (and I initialize MyItems before setting the DataContext):
public ObservableCollection<Item> MyItems;
Ultimately, my ListBox does not display anything. I tried adding elements after snapping, and they also do not appear.
What works if I install ItemSource in code instead of XAML:
MyItemsList.ItemsSource = App.ViewModel.MyItems;
Any tips on why this will happen? Thanks.
source share