Alex Rivera | Logout

how to use isChecked as a command parameter in that same check boxes command

Asked 2011-04-13T13:34:51.867
11

So I have a check box that fires a command using WPF/MVVM this works fine but I want to use the IsChecked property of the check box as a command parameter. I tried this.

  <CheckBox Margin="3" Content="Clear Selected OEM" 
                              Command="{Binding Path=ClearOemCommand}" 
                              CommandParameter="{Binding Path=IsChecked}"/>

Bu I get an error in the output window that says

System.Windows.Data Error: 40 : BindingExpression path error: 'IsChecked' property not found on 'object'

I would know how to use find ancestor if I wanted to use the property from another control but I am stumped here - it's probably easier than I think... Just not making the connection in my mind.

Thanks!

Edit
Report

1 Answer

36

Please add RelativeSource Self in CommandParameter

  <CheckBox Margin="3" Content="Clear Selected OEM" 
   Command="{Binding Path=ClearOemCommand}" 
   CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}" />
answered 2011-04-13T14:31:41.983

Your Answer