示例#1
0
        internal void AnimateLabel(Label label, 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(label, new NameScope());
            label.Background = new SolidColorBrush(color);
            label.RegisterName("Brush", label.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(label);
        }