【发布时间】:2015-06-12 14:33:18
【问题描述】:
我正在使用VisualTreeHelper 在一个看起来像这样的按钮上执行HitTest...
<Button Width="100"
Height="100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Purple">
Hello world
</Button>
但是,当我执行实际的 HitTest 时:
HitTestResult result = VisualTreeHelper.HitTest(_ContentHolder, new Point(xTransform, yTransform));
if (result != null)
{
}
返回的对象看起来像 VisualHit = {System.Windows.Controls.Border} 这对我来说不太有意义。
谁能提供任何指导,说明我可能做错了什么,我将如何返回实际的 Button 对象(这样我可以触发任何事件处理程序)以及为什么我可能会遇到这种行为?
【问题讨论】:
-
问题:在
Button上使用事件处理程序不是更容易吗? -
当然可以,但我试图在不占用实际鼠标的情况下模拟鼠标功能,据我所知,这是我唯一的选择。
-
你住在什么样的地狱里?
-
如果你想要特定的元素喜欢按钮,你可以使用 HitTestFilterCallback 来过滤元素。参考msdn.microsoft.com/en-us/library/ms752097(v=vs.110).aspx
-
@MikeEason 哈哈哈哈哈哈。我什至无法开始描述它...如果您有兴趣了解更多信息,请查看此链接msdn.microsoft.com/en-us/library/…,我正在尝试模拟称为 KinectRegion 的东西