开发者

how do i bind menuitem.click to a command in a different view model

I have a contextmenu, the itemsource is bound to an observable collection i need to bind the MenuItem.Click to a command in my viewmodel.. HOW DO I DO THIS?

i have my own view model but the co开发者_Go百科ntext menu items should be bounded to a different viewmodel..


Use RelativeSource Mode=FindAncestor to get to your parent Usercontrol and bind to the Path=DataContext.YourCommand. I believe you are trying to bind to the containing control's viewmodel.


If you dont like using RelativeSource, you can name your parent element and then using ElementName tag in the Binding extension:

If you want to bind between/cross different ViewModels, i believe you will have to use some sort of Event Broker/Aggregator. Have a look at Prism, it might give you some ideas

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜