如何在c#中设置Storyboard的TargetProperty?

时间:2014-03-14 09:19:42

标签: c# animation windows-runtime

我有这个xaml代码,我想用c#转换它:

<Storyboard>
                            <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="ellipse">
                                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="1"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>
</Storyboard>

我做了不同的尝试:

Duration duration = new Duration(TimeSpan.FromSeconds(1));
            Storyboard sb = new Storyboard();
            sb.Duration = duration;
            var da = new DoubleAnimationUsingKeyFrames();
            da.EnableDependentAnimation = true;
            da.Duration = duration;
            var ed1 = new EasingDoubleKeyFrame();
            ed1.KeyTime = TimeSpan.Parse("0");
            ed1.Value = 1;
            var ed2 = new EasingDoubleKeyFrame();
            ed2.KeyTime = TimeSpan.Parse("0:0:0.7");
            ed2.Value = 1;
            var ed3 = new EasingDoubleKeyFrame();
            ed3.KeyTime = TimeSpan.Parse("0:0:1");
            ed3.Value = 0;
            da.KeyFrames.Add(ed1);
            da.KeyFrames.Add(ed2);
            da.KeyFrames.Add(ed3);
            Storyboard.SetTarget(da, lgbStroke);
            Storyboard.SetTargetProperty(da, "(Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Offset)");
            sb.Children.Add(da);
            sb.Begin();

但是我得到了这个例外: WinRT信息:无法解析指定对象上的TargetProperty(Shape.Stroke)。(GradientBrush.GradientStops)[0]。(GradientStop.Offset)。

有人知道如何解决这个问题吗? 提前致谢

0 个答案:

没有答案