Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color animation not working

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?

like image 883
Cobold Avatar asked May 09 '11 19:05

Cobold


1 Answers

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" />
like image 110
Drew Noakes Avatar answered Oct 06 '22 01:10

Drew Noakes