C# 在触摸坐标处获取UI元素

C# 在触摸坐标处获取UI元素,c#,wpf,touch,coordinates,C#,Wpf,Touch,Coordinates,我相信我已经读过,有一种方法可以在WPF应用程序中获得触地坐标,并找出触地下方的UI元素。有人能帮忙吗?您必须对可视化树进行一次检查 下面是一个鼠标点击的例子(但在这方面触摸或多或少是相同的): 其他的重载可能会给您带来多点视觉效果。让您的UI元素像这样扩展UIElement类: class MyUIElement : UIElement { protected override void OnManipulationStarting(System.Windows.Inp

我相信我已经读过,有一种方法可以在WPF应用程序中获得触地坐标,并找出触地下方的UI元素。有人能帮忙吗?

您必须对可视化树进行一次检查

下面是一个鼠标点击的例子(但在这方面触摸或多或少是相同的):


其他的重载可能会给您带来多点视觉效果。

让您的UI元素像这样扩展UIElement类:

class MyUIElement : UIElement
    {
        protected override void OnManipulationStarting(System.Windows.Input.ManipulationStartingEventArgs e)
        {
            base.OnManipulationStarting(e);
            UIElement involvedUIElement = e.Source as UIElement;

            // to cancel the touch manipulaiton:
            e.Cancel();
        }
    }
involveduielment应该保存引发触摸事件的UI元素,如果需要取消对特定元素的操作,只需调用
e.cancel()


我希望这会有帮助

为什么你想知道UI元素在这个触摸屏的下方?是否需要将其从操作中排除?你什么时候需要它?在manipulation delta?我知道,我一直在想如何从页面滑动操作中排除我的按钮。请看这里:本例中的myCanvas是什么?如果我只想从操作中过滤出内容,该怎么办?
class MyUIElement : UIElement
    {
        protected override void OnManipulationStarting(System.Windows.Input.ManipulationStartingEventArgs e)
        {
            base.OnManipulationStarting(e);
            UIElement involvedUIElement = e.Source as UIElement;

            // to cancel the touch manipulaiton:
            e.Cancel();
        }
    }