IgorP

Hello,

is there s straight way how to tell a FrameworkElement (for example to a button) that his context menu should pop up on mouse enter event and not on mouse right click


Re: Windows Presentation Foundation (WPF) [ContextMenu] Show on mouse over and not on right click

Zodd

All you need to do is capture the mouse event that you want to trigger the context menu and write the following code.

UIFrameworkElement.ContextMenu.IsOpen = true;

You will also need to handle the event that should cause the context menu to close.

Example:

<TextBox Name="TestText" Width="200" Height="20" PreviewMouseMove="OpenContext">

<TextBox.ContextMenu>

<ContextMenu Name="Context">

<MenuItem Header="Test"/>

</ContextMenu>

</TextBox.ContextMenu>

</TextBox>

private void OpenContext(Object sender, RoutedEventArgs args)

{

TestText.ContextMenu.IsOpen = true;

}





Re: Windows Presentation Foundation (WPF) [ContextMenu] Show on mouse over and not on right click

IgorP

Tnx Zodd. IsOpen is the thing I was looking for.