Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Pass events from an overlying Canvas to an underlying Canvas's children?

$
0
0

Hello all, I have the following scenario:

A Window consisting of a Grid. Filling the Grid I have an InkCanvas underlying a regular Canvas on top of it (in the ZIndex sense). At run time I am adding Shape objects to the underlying InkCanvas's Children collection. Each Shape object is handling its own PreviewMouseMove event.

On the overlying Canvas object I am handling the MouseMove event. In this MouseMove event, based on some condition I either do some custom drawing on the overlying Canvas or, if the condition isn't satisfied, I need to pass the event through (as if the overlying Canvas isn't hit test visible). The problem is that I can't seem to get the Shape objects (that I've created and added to the underlying InkCanvas) to respond to their PreviewMouseMove events when the mouse moves over them.

It seems that what I need here is a tunneling event starting at the underlying InkCanvas and spreading to the Shape objects in its collection. So, in the overlying Canvas MouseMove event I check for the previous drawing condition and, if false, I attempt to pass the event through to the underlying InkCanvas via:

MouseEventArgs ePassThrough = new MouseEventArgs(Mouse.PrimaryDevice, 0);
ePassThrough.RoutedEvent = Mouse.PreviewMouseMoveEvent;
underlyingInkCanvas.RaiseEvent(ePassThrough);
This seems to work as the underlying InkCanvas's PreviewMouseMove event will indeed fire. However, if I move the mouse over any of the underlying InkCanvas's Shape object children, their individual PreviewMouseMove events do not fire. What am I missing here? Thank you all in advance.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>