Avalonia
Avalonia copied to clipboard
Open/close menu events are confusing
The following events are available on Menu
/ContextMenu
:
-
MenuBase.MenuOpened
-
ContextMenu.ContextMenuOpening
-
ContextMenu.ContextMenuClosing
I see a few issues here:
- The
MenuOpened
event is inherited byContextMenu
meaning that its open event has theMenu
prefix but its opening event has theContextMenu
prefix - Why is a cancelable
Closing
event needed? I've never seen a context menu that can't be closed, and having one sounds like a problem - Why are the context menu events not routed events?
- There should probably be an
Opening
event onMenu
too (though it shouldn't be cancelable)
I suggest the following;
-
MenuBase
hasOpened
andClosed
-
ContextMenu
has a cancelableOpening
-
Menu
has a non-cancelableOpening
- The closing event is removed from
ContextMenu
@WojciechKrysiak you implemented ContextMenuOpening
/Closing
- what do you think?
I have no preference either way - the only reason I implemented it like that was to mirror WPF naming and behavior, as you can mark the event as handled through its args. This has the same effect as cancelling it.
As for why it wasn't done as a routed event - I can't remember, but most likely lack of skill back then.
I agree that unifying the naming is a good aim, but it would introduce additional work for people porting from WPF.
Also, ToolTip events https://github.com/AvaloniaUI/Avalonia/pull/15493