无法处理previewMouseDown [英] Not able to handle PreviewMouseDown

查看:329
本文介绍了无法处理previewMouseDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿;我有一个用户控件以下可视hyerarchy:

Hey; I have the following visual hyerarchy in a usercontrol:

网格 - >帆布 - > MyContentControl

Grid -> Canvas -> MyContentControl

MyContentControl是自ContentControl派生的类具有在顶部装饰器是一个矩形,这是为了更容易地点击特定对象(增加命中测试区域)。装饰器是present在任何时候,但与透明背景。

MyContentControl is a class derived from ContentControl that has an adorner on top that is a rectangle, this is to make it easier to click on certain objects (increase hit testing area). The adorner is present at all times, but with transparent background.

我想看看当我点击的用户控件的codebehind一个MyContentControl提出的previewMouseDown事件,但事件似乎并没有得到提升,原来只有在装饰器的水平。

I would like to see the PreviewMouseDown events raised when I click on a MyContentControl from the usercontrol's codebehind, but the event does not seem to be raised there, only at the adorner level.

本次活动是在装饰器级处理,但e.IsHandled未设置为true,所以应该继续起泡或隧道。从我读,previewMouseDown是隧道,并IIRC,它应该被提出在用户控件第一。

The event is handled at the adorner level, but e.IsHandled is not set to true, so it should continue bubbling or tunneling. From what I read, PreviewMouseDown is tunneling, and IIRC, it should have been raised at the usercontrol first.

我缺少的东西?

感谢你。

推荐答案

既然你描述的实际可视的树看起来像这样的结构:

Given the structure that you described the actual visual tree will look something like this:

Window
 -> Grid
    -> Canvas
       -> MyContentControl
 -> AdornerLayer
    -> MyContentControlAdorner

正如你看到的,你的装饰器( MyContentControlAdorner )位于比您的自定义控制树的不同分支。这是因为装饰器被放置称为一个特殊的元素 AdornerLayer 里面。这样的 AdornerLayer 通常直接顶级元素中的位置(如窗口)。

As you see, your adorner (MyContentControlAdorner) is located in the different branch of the tree than your custom control. This is because adorners are placed inside a special element called AdornerLayer. Such AdornerLayer is usually located directly inside the top level element (such as Window or Page).

因此​​,考虑到所有这一切,应该明确的是,如果一个事件引发的装饰器它将隧道通过以下路径:窗口 - > AronerLayer - > MyContentControlAdorner

So, considering all of that, it should be clear that if an event is raised in the adorner it will tunnel by the following path: Window -> AronerLayer -> MyContentControlAdorner.

话虽这么说,你不能在位于不同的子树(即使它们是在另一个上面放置一个)两个元素处理鼠标事件。

That being said, you cannot handle a mouse event on two elements that are located in different subtrees (even though they are placed one on top of another).

这篇关于无法处理previewMouseDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆