我MainWindows.xaml
包含两个 Controls 元素。第一个与 连接,MapView.xaml
<Controls:MapView />
第二个与连接InfoView.xaml
<Controls:InfoView />
。现在我想从Object的InfoView dataContext
对象执行方法。InfoViewModel
MapView DataContext
MapViewModel
我怎样才能做到这一点?
MapView.xaml.cs
public MapView()
{
InitializeComponent();
_mapViewModel = new MapViewModel();
this.DataContext = _mapViewModel;
}
InfoView.xaml.cs
public InfoView()
{
InitializeComponent();
_infoViewModel = new InfoViewModel();
this.DataContext = _infoViewModel;
}