In my App.xaml.cs I have a global view model
public partial class App : Application
{
public static ViewModel viewModel = new ViewModel();
}
and I've always set data context in the code behind like this
public MainWindow(){
...
DataContext = App.viewModel;
...
}
However I want to try doing the same thing but in the XAML. How do I select the class and static property from the XAML? So far I have in my UserControl
<UserControl ...
xmlns:global="clr-namespace:MyMainNamespace"
(App would be under that namespace like this MyMainNamespace.App)
and then I can select 'App' just fine from global like this
<UserControl.Resources>
<global:App x:Key="test"></global:App>
</UserControl.Resources>
<UserControl.DataContext>
??
</UserControl.DataContext>
And further down in the user control I have a combo box that I want to bind to an observable collection inside the viewModel
<Grid>
<ComboBox Width="150" Height="25" HorizontalAlignment="Left" VerticalAlignment="Top" ></ComboBox>
</Grid>
Edit: I was trying to model my solution after this answer https://stackoverflow.com/a/23714054/1462656
But I could not find a way to select the viewModel object from App without it giving me syntax errors