1、全局的ViewModel绑定:
a)设定全局的ViewModel(App.xaml中):
1 <Application x:Class="MyTest.App" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:local="clr-namespace:MyTest" 5 StartupUri="MainWindow.xaml"> 6 <Application.Resources> 7 <local:MainViewModel x:Key="mainVM"/> 8 </Application.Resources> 9 </Application>
b)绑定全局的ViewModel(MainWindow中):
1 <Window x:Class="MyTest.MainWindow"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x