自定义 TouchDevice 在不正确的位置触发 Touch 事件

Custom TouchDevice triggers Touch events at incorrect position

我正在使用自定义 TouchDevice(下面的代码)与 UIElement 交互。此 TouchDevice 导致 TouchEnter 和 TouchLeave 事件在我传递给 Move(x,y) 的屏幕坐标右下角的 UIElement 上触发,而不是在这些坐标处的 UIElement 上触发。我该如何解决这个问题?

我的 Surface Pro 3 平板电脑(触摸屏,Windows 8.1)出现了这个问题,但我的台式机(没有触摸屏,Windows 7)没有出现这个问题。

我首先假设原因是 GetTouchPoint(IInputElement relativeTo) 的错误实现。但是,此方法仅在 relativeTo 设置为 null 时调用。

public class CustomTouchDevice : TouchDevice
    {
        public Point Position { get; set; }

        private GazeTouchDevice(int id) : base(id)
        {
            SetActiveSource(PresentationSource.FromVisual(Application.Current.MainWindow));
        }

        public void Move(int x, int y)
        {
            if(!IsActive)
            {
                Activate();
                ReportDown();
            }
            Position = new Point(x, y);
            ReportMove();
        }

        public void Lost()
        {
            if(IsActive)
            {
                ReportUp();
                Deactivate();
            }
        }

        public override TouchPoint GetTouchPoint(IInputElement relativeTo)
        {
            Point point = Position;
            if(relativeTo != null)
            {
                point = this.ActiveSource.RootVisual.TransformToDescendant((Visual)relativeTo).Transform(Position);
            }
            Rect rect = new Rect(point, new Size(1, 1));
            return new TouchPoint(this, point, rect, TouchAction.Move);
        }

        public override TouchPointCollection GetIntermediateTouchPoints(IInputElement relativeTo)
        {
            return new TouchPointCollection();
        }
   }

提前致谢!

替换 GetTouchPoint 的第一行解决了问题:

Point point = ActiveSource.RootVisual.PointFromScreen(Position);

显然,我的应用程序使用的坐标系与平板电脑上的屏幕坐标系不同。我怀疑 WPF 透明地选择不在超高清平板电脑屏幕 (2160x1440 px / 216 ppi) 上使用全分辨率。