A custom RoutedCommand is used by some menuItems; I would like to use the same RoutedCommand with checkboxes :
<CheckBox Command="local:MainWindow.SwitchContextCommand">
The compiler gives no error, but when i lauch the app, I get an exception telling me that the Command value can't be null and consequently SwitchContextCommand can't be attached to the checkBox.Command.
The command works fine with menus.
First question : is this possible? I think I can answer myself on this one because the CheckBox class contains the properties Command and CommandParameters. It seems possible.
Second : How it works ? With MenuItems, CanExecute is called when the menu is displayed. What happens for a checkbox which is constantly displayed ? Called implicitly on click ?
Third : why it doesn't works ?
Thanks!
SwitchContextCommand is a static member on your MainWindow class, right?
try using this in your Command attribute:
Command="{x:Static local:MainWindow.SwitchContextCommand}"
I would expect your command to fire when checked, but I would try it and see.