Bonjour à tous,
Le but final de mon code est de créer un écran permettant de réorganiser l'emplacement de boutons à l'aide d'un drag and drop. Le code "métier" fonctionne très bien (les boutons se replacent bien comme il faut), cependant l'animation de replacement ne fonctionne pas tout à fait comme je le souhaiterais :
- Pour un déplacement sur l'axe X -> pas de problème
- Pour un déplacement sur l'axe Y -> pas de problème
- Pour un déplacement sur les deux axes, les animations se font l'une après l'autre alors que je souhaiterais qu'elles s’exécutent en parallèle (comme un ParalleleTimeline de XAML).
Voici la fonction qui fait les changements de positions :
Comment donc dire au StoryBoard qu'il doit les exécuter de concert ?
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
39
40
41
42
43
44 public static void changeOrder(Panel pan, int direction, Point depart) { if (pan.Children.Count == 0) { UIElement elt = null; Panel nextPanel; if (direction > 0) nextPanel = (pan.Parent as Panel).Children[(pan.Parent as Panel).Children.IndexOf(pan) + 1] as Panel; else nextPanel = (pan.Parent as Panel).Children[(pan.Parent as Panel).Children.IndexOf(pan) - 1] as Panel; elt = nextPanel.Children[0]; TranslateTransform trans = new TranslateTransform(); elt.RenderTransform = trans; Point arrivee = elt.TransformToAncestor(Application.Current.Windows[Application.Current.Windows.Count - 1]).Transform(new Point(0, 0)); DoubleAnimation x = new DoubleAnimation(depart.X - arrivee.X, TimeSpan.FromSeconds(1)); x.FillBehavior = FillBehavior.Stop; DoubleAnimation y = new DoubleAnimation(depart.Y - arrivee.Y, TimeSpan.FromSeconds(0.5)); y.FillBehavior = FillBehavior.Stop; Storyboard.SetTarget(x, elt); Storyboard.SetTargetProperty(x, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)")); Storyboard.SetTarget(y, elt); Storyboard.SetTargetProperty(y, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); Storyboard sb = new Storyboard(); sb.Children.Add(x); sb.Children.Add(y); sb.Completed += delegate { depart = arrivee; nextPanel.Children.Remove(elt); pan.Children.Add(elt); changeOrder(nextPanel, direction, depart); }; sb.Begin(elt as FrameworkElement); } }
Merci d'avance.
Gurdil
Partager