Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Context menu on left click

I have a WPF application..In which I have an Image control in Xaml file.

On right click of this image I have a context menu.

I would like to have same to be displayed on "Left click" also.

How do I do this in MVVM way ?

like image 632
Relativity Avatar asked Nov 29 '10 16:11

Relativity


1 Answers

Here is a XAML only solution. Just add this style to your button. This will cause the context menu to open on both left and right click. Enjoy!

<Button Content="Open Context Menu">     <Button.Style>         <Style TargetType="{x:Type Button}">             <Style.Triggers>                 <EventTrigger RoutedEvent="Click">                     <EventTrigger.Actions>                         <BeginStoryboard>                             <Storyboard>                                 <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">                                     <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>                                 </BooleanAnimationUsingKeyFrames>                             </Storyboard>                         </BeginStoryboard>                     </EventTrigger.Actions>                 </EventTrigger>             </Style.Triggers>             <Setter Property="ContextMenu">                 <Setter.Value>                     <ContextMenu>                         <MenuItem />                         <MenuItem />                     </ContextMenu>                 </Setter.Value>             </Setter>         </Style>     </Button.Style> </Button> 
like image 168
Ben Wilde Avatar answered Sep 28 '22 01:09

Ben Wilde