0
我正在使用自定义TouchDevice(以下代码)与UIElements进行交互。这个TouchDevice导致TouchEnter和TouchLeave事件在UIElements上触发到屏幕坐标的右下角,我传递给Move(x,y)
而不是在这些坐标上的UIElement。我该如何解决?自定义TouchDevice触发不正确位置的触摸事件
在我的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();
}
}
在此先感谢!