SurfaceInkCanvas
でTouchDevice
としてAnoto-Penを使用しようとしています。
ペンは、用紙上に印刷された座標系を使用してその位置を導出し、この位置データをアプリケーションに送ります。ここでは、をサブクラス化してTouchDevice
にサブクラス化し、TouchDevice.ReportDown();
,TouchDevice.ReportMove()
などを使用して送信位置データとイベントを変換するようにしようとしています。ScatterViewItems
を移動し、ボタンのクリックを処理しています。Microsoft Surfaceウィンドウでタッチ入力をシミュレートする
今問題は、私がInkCanvas
に書き込もうとすると、点だけが描画されるということです。解雇されたイベントを観察した後、InkCanvas
はイベントOnTouchMove
を受け取っていないようです。
私はSurfaceInkCanvas
にTouchDown
、TouchMove
とTouchUp
のイベントハンドラを登録。 TouchDown
はトリガーされません。 TouchMove
とTouchUp
の場合は、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
に次のコードを持っており、それは、ペン入力が発生するたびに呼び出されます。
public void HandleEvent(object sender, EventArgs args)
{
if (typeof(PointInputArgs).IsAssignableFrom(args.GetType()))
{
PenPointInputArgs pointArgs = (PenPointInputArgs)args;
switch (pointArgs.EventType)
{
case InputEvent.Down: touchDevice1.PenDown(pointArgs, this.Dispatcher); break;
case InputEvent.Up: touchDevice1.PenUp(pointArgs, this.Dispatcher); break;
case InputEvent.Move:
case InputEvent.MoveDown: touchDevice1.PenMove(pointArgs, this.Dispatcher); break;
}
}
}
は、事前にありがとうございます。