Hello,
J'ai mis en place une gestion de plusieurs points sur un Canvas avec dans un premier temps la détection des actions Down:
Et ensuite la gestion des actions move:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 private void Touch_FrameReported(object sender, TouchFrameEventArgs e) { // Itération dans les points foreach(System.Windows.Input.TouchPoint CurrentTouchPoint in e.GetTouchPoints(this.CanvasFirewall)) { // Analyse de l'action du point switch(CurrentTouchPoint.Action) { case TouchAction.Down: #region Gestion des descentes // Analyse du type de l'objet en dessous de la touche if(CurrentTouchPoint.TouchDevice.DirectlyOver is Image) { // Récupération de l'objet image Image CurrentImage = CurrentTouchPoint.TouchDevice.DirectlyOver as Image; // Analyse du nom de l'image if(CurrentImage.Name.StartsWith("Atom#")) { // Initialisation d'un point suivi TrackedTouchPoint NewTrackedTouchPoint = new TrackedTouchPoint(CurrentTouchPoint.TouchDevice.Id,CurrentTouchPoint.Position); // Ajout du point dans la collection this.TrackedTouchPoints.Add(NewTrackedTouchPoint); } } #endregion ...
Dans le Canvas se trouve 4 images qui peuvent être déplacées. Si j'en prend une et que je la déplace en direction d'une autre il se passe deux choses:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 ... case TouchAction.Move: #region Gestion des mouvements // Analyse du type de l'objet en dessous de la touche if(CurrentTouchPoint.TouchDevice.DirectlyOver is Image) { // Récupération de l'objet image Image CurrentImage = CurrentTouchPoint.TouchDevice.DirectlyOver as Image; // Analyse du nom de l'image if(CurrentImage.Name.StartsWith("Atom#")) { // Recherche du point dans la liste des points précédents foreach(TrackedTouchPoint PreviousCurrentTouchPoint in this.TrackedTouchPoints) { // Comparaison des identifiants if(CurrentTouchPoint.TouchDevice.Id == PreviousCurrentTouchPoint.ID) { // Mise à jour de la transformation de l'image ((CompositeTransform)CurrentImage.RenderTransform).TranslateX += System.Math.Round(CurrentTouchPoint.Position.X - PreviousCurrentTouchPoint.Position.X,0); // Mise à jour de la transformation de l'image ((CompositeTransform)CurrentImage.RenderTransform).TranslateY += System.Math.Round(CurrentTouchPoint.Position.Y - PreviousCurrentTouchPoint.Position.Y,0); // Mise à jour de la position du point suivi PreviousCurrentTouchPoint.Position = CurrentTouchPoint.Position; this.TextBlockDeltaX.Text = "X= " + CurrentTouchPoint.Position.X.ToString(); this.TextBlockDeltaY.Text = "Y= " + CurrentTouchPoint.Position.Y.ToString(); // Sortie break; } } } } #endregion ...
1. L'image passe dessus/dessous l'autre et la deuxième ne bouge pas.
2. L'image passe dessus/dessous l'autre et les deux bougent.
Et là je comprends pas pourquoi vue que je fais une identification de l'Id !
J'ai l'impression que l'ordre d'ajout dans la collection Children du Canvas à un impact sur l'interaction ....
Merci
Partager