RoutedCommand.Execute not firing, but CanExecute does and set e.CanExecute to true

I'm having a problem with a custom Command that I'm setting on a button. Specifically the CanExecute method of my custom RoutedCommand fires, and is hardcoded to always set e.CanExecute = true, but the actual Execute event (called OnNoteClose) never gets fired.

Here's the specifics:

The button I set the Command on is actually the StickyNoteClose button for the StickyNoteControl used in WPF Annotations (yes I know we're probably not supposed to try to do this with Annotation-related stuff, but the Annotation functionality right now just isn't customizable enough). In my Window.Resources in the Style definition for

StickyNoteCloseButtonStyleKey I have this line:

Style x:Key="StickyNoteCloseButtonStyleKey" BasedOn="{StaticResource StickyNoteButtonStyleKey}" TargetType="{x:Type Button}" >

<Setter Property="Command" Value="local:MyCustomCommandClass.MyCustomCommand"/>

Then in the local namespace I have this code:

publicclassMyCustomCommandClass

{

privatestaticRoutedCommand _myCustomCommand;

static AddNoteWrappedCommand()

{

_myCustomCommand=newRoutedCommand("Enable MouseOvers",typeof(Window));

CommandManager.RegisterClassCommandBinding(typeof(Window),

newCommandBinding(_myCustomCommand, OnNoteClosed, CanMouseOversExecute));

}

publicstaticRoutedCommandMyCustomCommand

{

get

{

return _myCustomCommand;

}

}

privatestaticvoid CanMouseOversExecute(object target,CanExecuteRoutedEventArgs e)

{

e.CanExecute =true;

}

privatestaticvoid OnNoteClosed(object sender,ExecutedRoutedEventArgs e)

{

System.Console.WriteLine("got here");

}

So I have a theory that it might be something specific to the StickyNoteControl close button. For a test, I just created my own normal button and set the Style attribute on it to StickyNoteCloseButtonStyleKey, and sure enough, when I clicked it everything worked fine. But the StickyNoteControl's close button won't and because you never really get a reference to the StickyNoteControl, there's not much else I can do.

Interestingly enough, I came up with a hack that works. All I have to set is set this CommandParameter on the close button for the sticky note style:

<Setter Property="CommandParameter" Value="{Binding Path=IsPressed, RelativeSource={RelativeSource Self}}"/>

Then, in the CanMouseOversExecute method I just check the e.Parameters and if it's true, I can execute the code that does the work I care about. So that's my workaround, but I'd love to know why it's not working as I'd expect. Thoughts?

[5264 byte] By [adajos] at [2008-1-9]

Visual Studio Orcas

Site Classified