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?
Background is of type Brush which cannot be animated with a ColorAnimaion. However, SolidColorBrush has a Color property, so you can do something like: