WPF: Binding a ContextMenu to an MVVM Command?

See this article from Justin Taylor for a workaround.

Up vote 3 down vote favorite share g+ share fb share tw.

Let's say I have a Window with a property returning a Command (in fact, it's a UserControl with a Command in a ViewModel class, but let's keep things as simple as possible to reproduce the problem). The following works: But the following does not work. The error message I get is System.Windows.

Data Error: 4 : Cannot find source for binding with reference 'ElementName=myWindow'. BindingExpression:Path=MyCommand; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand') Why? And how do I fix this?

Using the DataContext is not an option, since this problem occurs way down the visual tree where the DataContext already contains the actual data being displayed. I already tried using {RelativeSource FindAncestor, ...} instead, but that yields a similar error message. EDIT (Solution): Based on HCLs answer, this is what I ended up using: ... c# wpf data-binding xaml mvvm link|improve this question edited Aug 30 '10 at 15:34 asked Aug 27 '10 at 11:01Heinzi34.7k44493 74% accept rate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions