There is also this way of specifying the viewmodel:
using Wpf = System.Windows;
public partial class App : Wpf.Application //your skeleton app already has this.
{
protected override void OnStartup( Wpf.StartupEventArgs e ) //you need to add this.
{
base.OnStartup( e );
MainWindow = new MainView();
MainWindow.DataContext = new MainViewModel( e.Args );
MainWindow.Show();
}
}
<Rant>
All of the solutions previously proposed require that MainViewModel
must have a parameterless constructor.
Microsoft is under the impression that systems can be built using parameterless constructors. If you are also under that impression, go ahead and use some of the other solutions.
For those that know that constructors must have parameters, and therefore the instantiation of objects cannot be left in the hands of magic frameworks, the proper way of specifying the viewmodel is the one I showed above.
</Rant>