1

I have defined Storyboard with DoubleAnimation in it and I need to change From value in code-behind before starting the animation. How can I do it?

This doesn't work - I get an exception Object reference not set to an instance of an object.

<Storyboard x:Key="SB_showhide" Duration="0:0:1">
    <DoubleAnimation x:Name="move" Storyboard.TargetProperty="(Window.Left)" From="0" To="500" />
</Storyboard>

((DoubleAnimation)FindName("move")).From = 200;
BeginStoryboard((Storyboard)FindResource("SB_showhide"));
Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65

1 Answers1

5

This should work:

var storyboard = (Storyboard)Resources["SB_showhide"];
var move = (DoubleAnimation)storyboard.Children[0];
move.From = 200;
Clemens
  • 123,504
  • 12
  • 155
  • 268