I have a button named "b", which background I want to change from black to white, but it doesn't work.
The error:
'System.Windows.Media.Animation.ColorAnimation' animation object cannot be used to animate property 'Background' because it is of incompatible type 'System.Windows.Media.Brush'.
My code:
Dim changeColor As New Animation.ColorAnimation
changeColor.From = Colors.Black
changeColor.To = Colors.White
changeColor.Duration = TimeSpan.FromSeconds(0.2)
Animation.Storyboard.SetTarget(changeColor, b)
Animation.Storyboard.SetTargetProperty(changeColor, New PropertyPath(BackgroundProperty))
Dim sb As New Animation.Storyboard
sb.Children.Add(changeColor)
sb.Begin()
Have any ideas?
It's worth noting that the same problem can be addressed in XAML using an expression of form:
<ColorAnimation Duration="0:0:0.2" From="Black" To="White"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Storyboard.TargetName="Body" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With