I have the following XAML:
Per the MSDN documentation...
ContextMenu itself is a FrameworkElement derived class, but the ContextMenuClosing event will not be raised by a context menu directly. Instead, the event is raised from the element that "owns" the context menu as a property and is only raised when a user attempts to close a context menu in the UI.
You would need to adjust your code so that the handler is defined solely on the DropDownButton
as you have done. If there is a nested ContextMenu
then the nested ContextMenu
will obviously raise the event.
<local:DropDownButton ContextMenuClosing="colorPallete_ContextMenuClosing">
...
</local:DropDownButton>
Using a Button
it would look like this...
<Button ContextMenuClosing="ContextMenu_ContextMenuClosing">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Go"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
..where when the ContextMenu
containing the MenuItem
closes; the event will be raised and the handler will be called.
Not certain what DropDownButton
control you are using so I can't comment on what the DropDown
property is and how you are nesting your ContextMenu
.