开发者

Can I set IsHitTestVisible to false only for right-button events?

Obviously, the straightforward answer to the question is "No", but what's the best way for me to achieve that kind of effect? To explain, here's a bit of background...

I have an app that displays an Image plus a couple of layers of overlaid shapes on that image. All of these are placed within a Grid cell, overlapping each other, with the image at the bottom of the local z-order. For speed, the overlays are implemented as classes derived from FrameworkElement and they create and manage their own visuals.

Here's a basic diagram (albeit exploded into 3D) of how the layers are arranged and what interaction they have/need:


overlapped_controls.png http://www.afterbang.co.uk/mal/stackoverflow/overlapped_controls.png


As you can see, the upper overlay must allow the user to drag out a new rectangle anywhere in the image. To that end, I've given it a transparent background, acting like a plate of glass on which you can draw. The obv开发者_开发知识库ious drawback of this is that it stops all mouse events passing through down to the lower layers.

I'd really like to only trap the left mouse button's events in that top layer's transparent area and let other events hit layers further down the z-order.

Is there a WPF-minded pattern I should be following for this kind of thing? Any kind of best practice or technique?

I'm still fairly fresh to WPF, but want to write a solution that's in tune with the API. Thanks.


I would use the PreviewMouseDown event on the elements that need to be right-clicked, and use LeftMouseDown on the elements that need to be left-clicked. The PreviewMouseDown event will still fire, but you can write handlers to ignore left clicks for it.

This is actually a pattern I'm using to display shapes on top of images, so that a user can circle a part of the image to highlight it. I have the PreviewMouseDown on the image, and it functions normally all the time, then I have a LeftMouseDown handler on any shapes so that they can be moved, deleted, etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜