跨MVVM中的视图模型的命令绑定 [英] Command binding across the view models in MVVM
本文介绍了跨MVVM中的视图模型的命令绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以建议我在除使用Messenger之外的视图模型中绑定命令。
请在下面找到我的代码。
我需要将MenuItem的命令与RelayCommand属性绑定,该属性存在于其他视图模型中。
下面是我尝试的方式。但是不是。
< igDock:ContentPane 标题 = 仪表板 x:名称 = dashboardWindow DataContext = {Binding Path = viewModels:DashboardViewModel。} AllowClose = 错误 >
< ContentControl 内容 = {Binding ElementName = panelUI,Path = DashboardControl,Mode = TwoWay} / >
< ContentControl.ContextMenu >
< ; ContextMenu &g t;
< MenuItem 标题 = 添加新平铺 命令 = {Binding ElementName = dashboardWindow,Path = viewModels:DashboardViewModel.AddTileContextMenuCommand} > < / MenuItem >
< / ContextMenu >
< / ContentControl.ContextMenu >
< / igDock:ContentPane >
解决方案
嘿......
我的问题解决了。
我刚刚使用我的视图模型分配了dashboardWindow DataContext。
我可以在窗口中获取命令。 :)
Hi,
Any one please suggest me a way to bind the command across the view models other than using Messenger.
Please find my code below.
I need to bind the command of MenuItem with RelayCommand property which exists in other view model.
Below is the way I tried out.it doesnot however.
<igDock:ContentPane Header="Dashboard" x:Name="dashboardWindow" DataContext="{Binding Path=viewModels:DashboardViewModel.}" AllowClose="False">
<ContentControl Content="{Binding ElementName=panelUI, Path=DashboardControl, Mode=TwoWay}"/>
<ContentControl.ContextMenu>
<ContextMenu>
<MenuItem Header="Add New Tile" Command="{Binding ElementName=dashboardWindow,Path=viewModels:DashboardViewModel.AddTileContextMenuCommand}"></MenuItem>
</ContextMenu>
</ContentControl.ContextMenu>
</igDock:ContentPane>
解决方案
Hey ...
My problem got solved.
I just assigned the dashboardWindow DataContext with my view model.
I could get the command in my window. :)
这篇关于跨MVVM中的视图模型的命令绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文