2

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!

joshperry
  • 41,167
  • 16
  • 88
  • 103
rockeye
  • 2,765
  • 2
  • 30
  • 44

1 Answers1

1

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.

jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182