Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Open/close menu events are confusing

Open grokys opened this issue 4 years ago • 2 comments

The following events are available on Menu/ContextMenu:

  • MenuBase.MenuOpened
  • ContextMenu.ContextMenuOpening
  • ContextMenu.ContextMenuClosing

I see a few issues here:

  1. The MenuOpened event is inherited by ContextMenu meaning that its open event has the Menu prefix but its opening event has the ContextMenu prefix
  2. 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
  3. Why are the context menu events not routed events?
  4. There should probably be an Opening event on Menu too (though it shouldn't be cancelable)

I suggest the following;

  • MenuBase has Opened and Closed
  • ContextMenu has a cancelable Opening
  • Menu has a non-cancelable Opening
  • The closing event is removed from ContextMenu

@WojciechKrysiak you implemented ContextMenuOpening/Closing - what do you think?

grokys avatar Aug 06 '20 14:08 grokys

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.

WojciechKrysiak avatar Aug 06 '20 15:08 WojciechKrysiak

Also, ToolTip events https://github.com/AvaloniaUI/Avalonia/pull/15493

maxkatz6 avatar May 12 '24 10:05 maxkatz6