locked
How to set TargetProperty of Storyboard in c#?

    Question

  • I have this xaml code and I want to convert it in 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>

    I have made different tries :

     

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

    but I get this exception :
    WinRT information: Cannot resolve TargetProperty (Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Offset) on specified object.

    Does anybody have any idea how to resolve this?
    Thanks in advance

    Friday, March 14, 2014 9:34 AM

Answers