In this simple sample I want to show a MessageBox
before the Context menu is showed.
I write this code on the ´XAML´:
<Border>
<Border.ContextMenu>
<ContextMenu ContextMenuOpening="ContextMenu_ContextMenuOpening">
<MenuItem Header="Select pic" IsEnabled="{Binding Path=ProductSelected}" />
<MenuItem Header="Paste pict" Name="miPaste" Click="miPaste_Click"/>
</ContextMenu>
</Border.ContextMenu>
<Image Stretch="Fill" Source="{Binding Path=Product.Picture}" />
</Border>
And I write this in the ´CS´:
private void ContextMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
MessageBox.Show("OPPENING");
}
I don't know why, when I press the right mouse button, the Context Menu appears but the MessageBox is never shown.
I believe ContextMenuOpening event should be defined for the control which has context menu opened on, not the context menu itself. See if code below would work for you:
<Border ContextMenuOpening="ContextMenu_ContextMenuOpening">
<Border.ContextMenu>
<ContextMenu >
<MenuItem Header="Select pic" />
<MenuItem Header="Paste pict" Name="miPaste" />
</ContextMenu>
</Border.ContextMenu>
</Border>
hope this helps, regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With