英語で読む

次の方法で共有


Touch.FrameReported イベント

定義

タッチ メッセージが送信されたときに発生します。

C#
public static event System.Windows.Input.TouchFrameEventHandler FrameReported;

イベントの種類

次の例では、FrameReported イベントを処理します。 タッチが をCanvasTouchDevice押すと、 が にCanvasキャプチャされます。 タッチが解除されると、 TouchDevice が解放されます。 タッチが を越えて移動すると、 CanvasId がオンになります。 最初のタッチから移動した場合、その位置が記録されます。 移動が 2 番目のタッチから来た場合は、最初のタッチの位置から 2 番目のタッチの位置に線が描画されます。

この例は、クラスの概要で使用できる大きな例の Touch 一部です。

C#
public partial class MainWindow : Window
{
    // Variables for tracking the position of two points.
    Point pt1, pt2 = new Point();
    
    public MainWindow()
    {
        InitializeComponent();
        Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
    }

    void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        if (this.canvas1 != null)
        {
            foreach (TouchPoint _touchPoint in e.GetTouchPoints(this.canvas1))
            {
                if (_touchPoint.Action == TouchAction.Down)
                {
                    // Clear the canvas and capture the touch to it.
                    this.canvas1.Children.Clear();
                    _touchPoint.TouchDevice.Capture(this.canvas1);
                }

                else if (_touchPoint.Action == TouchAction.Move && e.GetPrimaryTouchPoint(this.canvas1) != null)
                {   
                    // This is the first (primary) touch point. Just record its position.
                    if (_touchPoint.TouchDevice.Id == e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
                    {
                        pt1.X = _touchPoint.Position.X;
                        pt1.Y = _touchPoint.Position.Y;
                    }

                    // This is not the first touch point. Draw a line from the first point to this one.
                    else if (_touchPoint.TouchDevice.Id != e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
                    {
                        pt2.X = _touchPoint.Position.X;
                        pt2.Y = _touchPoint.Position.Y;

                        Line _line = new Line();
                        _line.Stroke = new RadialGradientBrush(Colors.White, Colors.Black);
                        _line.X1 = pt1.X;
                        _line.X2 = pt2.X;
                        _line.Y1 = pt1.Y;
                        _line.Y2 = pt2.Y;
                        _line.StrokeThickness = 2;
                        this.canvas1.Children.Add(_line);
                    }
                }

                else if (_touchPoint.Action == TouchAction.Up)
                {
                    // If this touch is captured to the canvas, release it.
                    if (_touchPoint.TouchDevice.Captured == this.canvas1)
                    {
                        this.canvas1.ReleaseTouchCapture(_touchPoint.TouchDevice);
                    }
                }
            }                        
        }
    }
}

注釈

フレームは、一連のマルチタッチ メッセージまたはタッチ ポイントの 1 つです。 イベントを処理 FrameReported し、イベント データから の詳細 TouchPoint にアクセスすることで、タッチに TouchFrameEventArgs 応答できます。

イベントでは FrameReported 、 や などの TouchDown 他の WPF 入力イベントと TouchMove同じイベント モデルは使用されません。 UI のオブジェクト ツリーを介してルーティングされる可能性がある要素固有のイベントとして公開されるのではなく、 FrameReported イベントはアプリケーション レベルで処理される 1 つのイベントです。 そのため、イベント ハンドラーの パラメーターを sender 使用して、タッチされる要素を特定することはできません。

適用対象

製品 バージョン
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10