Consider the following XAML:
<Window x:Class="ContextMenuEvent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" ContextMenuOpening="Window_ContextMenuOpening">
<Grid>
<Button>Ok</Button>
</Grid>
</Window>
Right-clicking the button causes ContextMenuOpening to fire, even though no context menu actually appearing.
Why is it happening? What can I do to get an even only when a context menu is REALLY opening?
I am aware I can use ContextMenu.Opened event, but this will only cover a single context menu, and I want to cover all the (existing) context menus in the form.
Not so sure why you’d use this approach. You can however easily check if a context menu would appear. Like this: