The following code was part of an answer I have received to solve a probem I have posted in SO. It works fine, however I’m curious if its allowed to manually invoke another event from within an
invocation-method with the EventArgs of the original event:
protected override void OnMouseLeftButtonUp( MouseButtonEventArgs e ) {
base.OnMouseLeftButtonDown( e );
}
I have seen this pattern frequently but never used it because I feared always that this could lead to sideeffects or problems in future versions of WPF. Has anyone the insight to tell me if such redirected event-invocations are save?
I would be very careful with doing this. If the event data contains stuff that is only relevant to the original event the other event handler can be confused by this data. Especially when it comes to events from external devices like the mouse.
Maybe this example you posted is ok, I don’t know. But I can definitely see a problem with doing the other way around, raising mouse down when you get a mouse up – the mouse down handler could (potentially, I have no idea if it does this) query the input device for the actual status of that mouse and they wouldn’t match. Or perhaps do some operation on the mouse that only works when it is pressed etc.
So in summary: It may work, but I would not rely on it unless you are 100% sure it won’t break under certain conditions