开发者

Passing mouse events to overlapped controls

My WPF user control consists of a few subcomponents, placed in such way that they overlap each other (sometimes completely), however they are on the same level on the visual tree (each subcomponent's parent is the main grid). I wish to pass mouse events from the topmost to the bottommost one, however default WPF's behavior passes them through the visual tree paths, not by their Z-order. Unfortunately, it is not possible to embed one in another (to take advantag开发者_如何学编程e of the default mechanisms). How may I resolve this problem?

Best regards -- Spook.


A straightforward solution would be to handle all events in your parent Grid by not attaching any handlers in the child controls and manually "route" the events based on child z-order to the grid's children.

It will require lots of manual work, but I can't seem to find any other way to implement custom routing strategies in WPF.


If your specific case requires that all of the subcomponents be at the same level in the visual tree, your best bet is probably to set the IsHitTestVisible flag to false for all of the subcomponents, catch the mouse events at the top-most level, then manually pick the subcomponent that is appropriate for the mouse event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜