locked
CanExecute handler is called, Executed handler is not called RRS feed

  • Question

  • XAML:

    <MenuItem Header="Rotation">
      <MenuItem Header="0°" Name="menuRotation0" IsCheckable="True" IsChecked="True" />
      <MenuItem Header="90°" Name="menuRotation90" IsCheckable="True" />
      <MenuItem Header="180°" Name="menuRotation180" IsCheckable="True" />
      <MenuItem Header="270°" Name="menuRotation270" IsCheckable="True" />
    </MenuItem>

    Code:

    // Class members:
    public static RoutedCommand CommandRotation0 = new RoutedCommand();
    public static RoutedCommand CommandRotation90 = new RoutedCommand();
    public static RoutedCommand CommandRotation180 = new RoutedCommand();
    public static RoutedCommand CommandRotation270 = new RoutedCommand();

    // Constructor:
    menuRotation0.Command = CommandRotation0;
    menuRotation90.Command = CommandRotation90;
    menuRotation180.Command = CommandRotation180;
    menuRotation270.Command = CommandRotation270;

    this.CommandBindings.Add(
         new CommandBinding(CommandRotation0, Rotation0, RotationEnabled));

    this.CommandBindings.Add(
         new CommandBinding(CommandRotation90, Rotation90, RotationEnabled));

    this.CommandBindings.Add(
         new CommandBinding(CommandRotation180, Rotation180, RotationEnabled));

    this.CommandBindings.Add(
         new CommandBinding(CommandRotation270, Rotation270, RotationEnabled));

    Result: RotationEnabled function is called, CommandRotation0 - CommandRotation270 are not called. What is wrong?

    I found also that if I create CommandBinding objects without RotationEnabled parameter, Execute handler is called.

    Sunday, September 10, 2006 2:16 PM

Answers