Reputation: 5779
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"));
Upvotes: 1
Views: 953
Reputation: 128061
This should work:
var storyboard = (Storyboard)Resources["SB_showhide"];
var move = (DoubleAnimation)storyboard.Children[0];
move.From = 200;
Upvotes: 5