Bonjour
Après avoir créé à la volée des Grids contenant en enfants un Canvas, un TextBlock et un rectangle
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
private UIElement CreateButton(int MinWidthButton, int advocatedHeightButton, NavigationStore storeItem, int heightCanvas)
        {
 ///Create Button with Colors Properties from CDiscount Assignation List
 
            #region Design GridButton
            Grid gridButton = new Grid();
            gridButton.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(advocatedHeightButton)});
            gridButton.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(MinWidthButton) });
            gridButton.Name = "gridButton" + storeItem.storeId;
 
            Canvas canvas = new Canvas();
            canvas.Background = ItemSiteColor.SetPropertiesFromItemSite(storeItem.storeColorName);
            canvas.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            gridButton.Children.Add(canvas);
            canvas.Height = 5;
            canvas.Name = "canvasTemplate"+storeItem.storeId.ToString();
 
            Rectangle rect = new Rectangle();
            rect.Fill = new SolidColorBrush(Colors.Transparent);
            rect.Height = gridButton.Height;
            rect.Width = gridButton.Width;
            gridButton.Children.Add(rect);
 
            TextBlock ButtonContentTxtBlck = new TextBlock();
            ButtonContentTxtBlck.Text = storeItem.storeName;
            ButtonContentTxtBlck.TextWrapping = TextWrapping.Wrap;
            ButtonContentTxtBlck.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            ButtonContentTxtBlck.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            #endregion
 
            gridButton.Children.Add(ButtonContentTxtBlck);
 
            /// Define Button Content from Item Informations
 
            gridButton.MinHeight = advocatedHeightButton;
            gridButton.MinWidth = MinWidthButton;
 
            /// Create Anonymous Method for Button Click Event
            gridButton.MouseLeftButtonDown += new MouseButtonEventHandler((s, arg) => { 
 
                ClickStoreButton(storeItem.storeId);
                _buttonIdSelected = storeItem.storeId;
                ResetCanvasOnStackPanel(heightCanvas);
                canvas.Height = advocatedHeightButton;
                });
 
            /// Create Anonymous Method for Button Mouse Enter Event
            gridButton.MouseEnter += new MouseEventHandler((s, arg) => {
                canvas.Height = advocatedHeightButton;
            });
 
            /// Create Anonymous Method for Button Mouse Leave Event
            gridButton.MouseLeave += new MouseEventHandler((s, arg) => {
                if (_buttonIdSelected == storeItem.storeId)
                {
                    canvas.Height = advocatedHeightButton;
                }
                else
                {
                    canvas.Height = 5;
                }
            });
            if (_buttonIdSelected == storeItem.storeId)
            {
                canvas.Height = advocatedHeightButton;
            }
            return gridButton;
}
Je voudrais réinitiliser tout mes canvas et pour celui sélectionné faire une animation
Donc j'appelle la méthode ResetCanvasOnStackPanel dans l'event clic gauche de ma mouse

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
private void ResetCanvasOnStackPanel(int heightCanvas)
        {
            foreach (Grid grid in StoreStckPnl.Children)
            {
 
                /// Get child canvas from Store Stack Panel
                var query = from gridElement in grid.Children
                            where gridElement.GetType() == typeof(Canvas)
                            select gridElement;
                Canvas canv = (Canvas)query.FirstOrDefault();
                if (canv.Height > heightCanvas)
                {
                    Storyboard sb = new Storyboard();
                    sb.SetValue(NameProperty, StoreStckPnl.Name);
                    DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();
 
                    Storyboard.SetTargetName(anim, canv.Name);
                    Storyboard.SetTargetProperty(anim, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleY)"));
                    anim.BeginTime = new TimeSpan(0, 0, 0);
 
                    EasingDoubleKeyFrame keyFrame0 = new EasingDoubleKeyFrame();
                    keyFrame0.KeyTime = TimeSpan.FromSeconds(0.1);
                    keyFrame0.Value = 10;
                    anim.KeyFrames.Add(keyFrame0);
 
                    sb.Children.Add(anim);
                    sb.Begin();
                }
 
                canv.Height = heightCanvas;
            }
        }
Sauf qu'il me sort une exception sur le Begin comme quoi le TargetNamen'est pas trouvable