Reputation: 43
I want to simulate a right click on datagrid in WPF, and a context menu pop up. But I found that the context menu is popped up via the PopupControlService which is internal to MS and I cannot access. Now I have the datagrid instance. How can I simulate a right click on this datagrid? Thank you all.
Upvotes: 1
Views: 757
Reputation: 295
DataGrid.RaiseEvent(new RoutedEventArgs(ContextMenuOpeningEvent));
Have you tried it?
Or
DataGrid.RaiseEvent(new RoutedEventArgs(MouseRightButtonDownEvent));
Look here: https://timscyclingblog.wordpress.com/2012/04/05/wpf-simulate-mouse-click-in-code-behind/
And also here: Raising WPF MouseLeftButtonDownEvent event
Upvotes: 1
Reputation:
To by-passe the problem you can create manually the context menu and show it in the code behind ?
Upvotes: 0