Проблема, с которой я столкнулся прошлой ночью (см. здесь ), заключалась в том, что использование Storyboard.SetTarget
работает только тогда, когда свойство, которое вы анимируете, является свойством FrameworkElement
или FrameworkContentElement
.
Вы на самом деле не анимируете Label.Background
, вы анимируете SolidColorBrush.Color
. Поэтому (по крайней мере, насколько я понимаю) вы должны создать область имен, дать вашей кисти имя и использовать Storyboard.SetTargetName
, чтобы установить ее в качестве цели.
Этот метод работает в C #; его перевод на VB должен быть простым:
void AnimateLabel(Label label)
{
// 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(Colors.MidnightBlue);
label.RegisterName("Brush", label.Background);
ColorAnimation highlightAnimation = new ColorAnimation();
highlightAnimation.To = Colors.Transparent;
highlightAnimation.Duration = TimeSpan.FromSeconds(1);
Storyboard.SetTargetName(highlightAnimation, "Brush");
Storyboard.SetTargetProperty(highlightAnimation, new PropertyPath(SolidColorBrush.ColorProperty));
Storyboard sb = new Storyboard();
sb.Children.Add(highlightAnimation);
sb.Begin(label);
}