从属性更改DoubleAnimation

时间:2015-04-12 15:09:52

标签: c# wpf animation

我已经使用DoubleAnimation定义了Storyboard,我需要在开始动画之前更改代码隐藏中的值。我该怎么办?

这不起作用 - 我得到一个异常对象引用未设置为对象的实例

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

1 个答案:

答案 0 :(得分:1)

这应该有效:

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