Exemple #1
0
        internal void AnimateTextBox(TextBox textBox, Color color) {
            // Attaching the NameScope to the label makes sense if you're only animating
            // things that belong to that label; this allows you to animate any number
            // of labels simultaneously with this method without SetTargetName setting
            // the wrong thing as the target.
            NameScope.SetNameScope(textBox, new NameScope());
            textBox.Background = new SolidColorBrush(color);
            textBox.RegisterName("Brush", textBox.Background);

            ColorAnimation highlightAnimation = new ColorAnimation();
            highlightAnimation.To = Colors.Transparent;
            highlightAnimation.Duration = TimeSpan.FromSeconds(3);

            Storyboard.SetTargetName(highlightAnimation, "Brush");
            Storyboard.SetTargetProperty(highlightAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

            Storyboard sb = new Storyboard();
            sb.Children.Add(highlightAnimation);
            sb.Begin(textBox);
        }