Touch.FrameReported 事件

定義

發生於傳送觸控訊息時。

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

事件類型

範例

下列範例會處理 FrameReported 事件。 當觸控按下 Canvas時,會 TouchDevice 擷取至 Canvas。 當觸控隨即解除時,會 TouchDevice 放開 。 當觸控在 之間 Canvas移動時, Id 會檢查 。 如果移動來自第一次觸控,則會記錄其位置。 如果移動來自第二個觸控,則會從第一個觸控的位置繪製線條到第二個觸控的位置。

此範例是類別概觀中提供之較大範例的 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);
                    }
                }
            }                        
        }
    }
}

備註

框架是一系列多重觸控訊息或觸控點中的畫面。 您可以處理FrameReported事件,並從事件數據存取的詳細TouchPointTouchFrameEventArgs數據,以回應觸控。

事件 FrameReported 不會與其他 WPF 輸入事件使用相同的事件模型,例如 TouchDownTouchMove。 事件不是公開為可能透過UI物件樹狀結構路由的專案特定事件,而是 FrameReported 在應用層級處理的單一事件。 因此,您無法使用 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