fire mouse events on both usercontrols
The thing is, I have 2 usercontrols, lets call them A and B. They both have MouseRightButtonDown and MouseRightButtonUp events and us开发者_开发技巧ercontrol A kinda overlaps B. Now when I right mouse click on A, the mouse event on B does not fire. When I disable the mouseevents on usercontrol A, the mouseevents on usercontrol B fires.
But how can I get them both to fire simultaneously?
(hope I've explained it clearly)
a bit hacky but this would work, bind the event handler only to the control 1 and call the other event handler like this:
private void textBlock1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("textBlock1_MouseRightButtonDown");
textBlock2_MouseRightButtonDown(sender, e);
}
private void textBlock2_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("textBlock2_MouseRightButtonDown");
}
personally I would not do this, I would do all my best to re-architect the logic and not have to call the other handler from one of the two controls, but without knowing more what your are doing, impossible to tell...
As we are talking about Silverlight here, I strongly suggest to look on how to work Routed Events, which is a mechanism which actually will help you to avoid event relaunching, as these are events that are traverse Visual Tree of your element, from top to bottom.
Definitely better then relaunching events.
精彩评论