简体   繁体   中英

Change DoubleAnimation From property

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"));

This should work:

var storyboard = (Storyboard)Resources["SB_showhide"];
var move = (DoubleAnimation)storyboard.Children[0];
move.From = 200;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM