模拟Microsoft Surface Window上的触摸输入

时间:2012-05-12 15:14:46

标签: c# touch device pixelsense inkcanvas

我正在尝试将Anoto-Pen用作TouchDevice SurfaceInkCanvas 笔使用打印在纸张上的坐标系统来获取其位置,然后将此位置数据发送到我的应用程序。在那里,我尝试通过继承TouchInput将其转换为TouchDevice,并使用TouchDevice.ReportDown();TouchDevice.ReportMove()等将发送位置数据和事件转换为.NET Touch-Events。 {1}}周围和处理按钮“点击”到目前为止工作。

现在的问题是,当我尝试在ScatterViewItems上写字时,只绘制了点。在观察了被触发的事件后,InkCanvas似乎没有收到InkCanvas个事件。

我在OnTouchMove上注册了TouchDownTouchMoveTouchUp的事件处理程序。永远不会触发SurfaceInkCanvasTouchDownTouchMove仅当我从TouchUp之外开始然后移动到其中的某个点时。{/ p>

以下是我SurfaceInkCanvas的代码:

TouchDevice

我的using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Input; using System.Text.RegularExpressions; using System.Windows; using PaperDisplay.PenInput; using System.Windows.Media; using System.Windows.Threading; namespace TouchApp { public class PenTouchDevice : TouchDevice { public Point Position { get; set; } public Person Person { get; set; } public PenTouchDevice(Person person) : base(person.GetHashCode()) { Person = person; } public override TouchPointCollection GetIntermediateTouchPoints(System.Windows.IInputElement relativeTo) { return new TouchPointCollection(); } public override TouchPoint GetTouchPoint(System.Windows.IInputElement relativeTo) { Point point = Position; if (relativeTo != null) { point = this.ActiveSource.RootVisual.TransformToDescendant((Visual)relativeTo).Transform(Position); } return new TouchPoint(this, point, new Rect(point, new Size(2.0, 2.0)), TouchAction.Move); } public void PenDown(PenPointInputArgs args, Dispatcher dispatcher) { dispatcher.BeginInvoke((Action)(() => { SetActiveSource(PresentationSource.FromVisual(Person.Window)); Position = GetPosition(args); if (!IsActive) { Activate(); } ReportDown(); })); } public void PenUp(PenPointInputArgs args, Dispatcher dispatcher) { dispatcher.BeginInvoke((Action)(() => { Position = GetPosition(args); if (IsActive) { ReportUp(); Deactivate(); } })); } public void PenMove(PenPointInputArgs args, Dispatcher dispatcher) { dispatcher.BeginInvoke((Action)(() => { if (IsActive) { Position = GetPosition(args); ReportMove(); } })); } public Point GetPosition(PenPointInputArgs args) { double adaptedX = args.Y - 0.01; double adaptedY = (1 - args.X) - 0.005; return new Point(adaptedX * Person.Window.ActualWidth, adaptedY * Person.Window.ActualHeight); } } } 中有以下代码,每次输入笔时都会调用它:

App.xaml.cs

提前谢谢。

1 个答案:

答案 0 :(得分:-1)

GetIntermediateTouchPoints一定不能返回一个空数组,它应至少包含一个点

public override TouchPointCollection GetIntermediateTouchPoints(System.Windows.IInputElement relativeTo)
{
    TouchPointCollection refCollection = new TouchPointCollection();
    refCollection.Add(GetTouchPoint(relativeTo));
    return refCollection;
}