MVVM User Control Issue

Posted by Burt on Stack Overflow See other posts from Stack Overflow or by Burt
Published on 2010-03-21T23:45:18Z Indexed on 2010/03/21 23:51 UTC
Read the original article Hit count: 405

Filed under:
|

I have a problem with commands in an MVVM application (I am only learning MVVM so go easy).

Valid XHTML

MyClassViewModel is set to the datacontext for MainForm1, MyList is bound to UserControl1 datacontext and each item in the list is represented by UserControl2. I am trying to fire MyCommand in UserControl2 using the following:

<CheckBox IsChecked="{Binding MyBool}" Command="{Binding Path=MyCommand}" CommandParameter="{Binding}">

I get the following error in the output:

System.Windows.Data Error: 39 : BindingExpression path error: 'MyCommand' property not found on 'object' ''MyObject''

From this error I know that WPF is looking for the command in the object bound to the UserControl2 what I really need is for it to look for the command in the MainForm1 datacontext (MyClassViewModel).

Is it possible to bubble up commands like this and if so how is it done?

Is bubbling up the command a good solution?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-binding