【发布时间】:2015-05-28 11:08:22
【问题描述】:
我正在使用自定义 TouchDevice(下面的代码)与 UIElements 交互。此 TouchDevice 导致 TouchEnter 和 TouchLeave 事件在我传递给Move(x,y) 的屏幕坐标右下角的 UIElements 上触发,而不是在这些坐标处的 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();
}
}
提前致谢!
【问题讨论】: