0

I would like to simulate/route right click on a WPF "control".

To make a long story short. I have an Adorner which should react to left click (so is hit test visible must be true) but at the same time I would like it to be "transparent" for the right clicks. (In another words i would like for a control under it to receive this click - btw right click makes Adorner disappear).

I tried to raise MouseRightButtonUp event on control directly under mouse (after Adorner disappears but it doesn't seem to work). I would like to avoid calling system functions (like mouse_event through P/Invoke). Can it be even done in wpf?

Hari Prasad
17k4 gold badges23 silver badges35 bronze badges
asked Sep 23, 2015 at 7:20
3
  • we need some code here. I'm guessing the transparency is done in an eventhandler that was created by you? In that case invoking should work... Commented Sep 23, 2015 at 7:26
  • 1
    Some code may help. I would think about MouseLeftButtonDown handled on the Adorner, any other MouseEventshould be routed to any underlying ÙIElement`. Commented Sep 23, 2015 at 7:26
  • Why don't you try with MouseDown Event? Commented Sep 23, 2015 at 7:32

1 Answer 1

1

As far as I remember, I had troubles with routing events and changing Adorners IsHitTestVisible property. The main problem was, if I recall it correctly, that adorner and controls are on different branches of visual tree, so routed events spawned on the adorner won't make it to your controls.

I can't say much without you providing the code, but the simplest thing that should work would be to find a control under your mouse position and do

 private void myAdorner_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
 MouseButtonEventArgs revent = new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, MouseButton.Right);
 revent.RoutedEvent = e.RoutedEvent;
 //find you control
 control.RaiseEvent(revent);
 }
answered Sep 23, 2015 at 12:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.