Lire en anglais

Partager via


Touch.FrameReported Événement

Définition

Se produit lorsqu'un message tactile est envoyé.

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

Type d'événement

Exemples

L’exemple suivant gère l’événement FrameReported . Lorsqu’une pression tactile appuie sur , Canvasle TouchDevice est capturé dans .Canvas Lorsque la pression tactile est levée, le TouchDevice est relâché. Lorsqu’une pression tactile se déplace sur le Canvas, est Id coché. Si le déplacement provient de la première touche, son emplacement est enregistré. Si le mouvement provient de la deuxième touche, une ligne est dessinée de la position de la première touche à la position de la deuxième touche.

Cet exemple fait partie d’un exemple plus large disponible dans la vue d’ensemble de la Touch classe.

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);
                    }
                }
            }                        
        }
    }
}

Remarques

Un cadre est un dans une série de messages ou de points tactiles multitouch. Vous pouvez répondre aux touches en gérant l’événement FrameReported et en accédant aux détails du à partir des données de l’événement TouchPointTouchFrameEventArgs .

L’événement FrameReported n’utilise pas le même modèle d’événement que d’autres événements d’entrée WPF, tels que TouchDown et TouchMove. Au lieu d’être exposé en tant qu’événement spécifique à un élément qui parcourt potentiellement l’arborescence d’objets d’une interface utilisateur, l’événement FrameReported est un événement unique qui est géré au niveau de l’application. Par conséquent, vous ne pouvez pas utiliser le sender paramètre du gestionnaire d’événements pour déterminer quel élément est touché.

S’applique à

Produit Versions
.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