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 ?
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 ?
XAML
C#
you only need add the code into function Image_MouseDown
e.Handled = true;
Then it will not disappear.
If you want to do this just in Xaml without using code-behind you can use Expression Blend's triggers support:
You can invent your own DependencyProperty which opens a context menu when image is clicked, just like this:
And here is a C# code for that property:
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!
you can bind the Isopen Property of the contextMenu to a property in your viewModel like "IsContextMenuOpen". but the problem is your can't bind directly the contextmenu to your viewModel because it's not a part of your userControl hiarchy.So to resolve this you should bing the tag property to the dataontext of your view.
Good luck.