在App.xaml.cs中
public partial class App : Application { private void Application_Startup(object sender, StartupEventArgs e) { /* create the window */ var mainWindow = new MainWindow(); this.MainWindow = mainWindow; mainWindow.Show(); /* attach the mainViewModel */ var mainViewModel = new MainViewModel(); mainWindow.DataContext = mainViewModel; } }
在App.xaml中
<Application x:Class="AvalonDock.MVVMTestApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> </Application.Resources> </Application>
原文:http://www.cnblogs.com/Markshome/p/7712303.html