Having created a new WPF 4.5 MVVM Light Application, I wanted to change the startup URI so that I could do some checks before the app starts. I made the following change to App.xaml:
<Application x:Class="MvvmLight1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MvvmLight1.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="MainWindow.xaml"
mc:Ignorable="d">
To:
<Application x:Class="MvvmLight1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MvvmLight1.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
And added an OnStartup
method to the App.xaml.cs
:
public partial class App : Application
{
static App()
{
DispatcherHelper.Initialize();
}
protected override void OnStartup(StartupEventArgs e)
{
//base.OnStartup(e);
MainWindow win = new MainWindow();
win.Show();
}
}
Doing this seems to change the context that the window runs in. I did try setting the data context to the MainViewModel, but this didn't seem to help.