如何为Silverlight Storyboard Begintime而不是xaml执行代码

时间:2011-08-09 16:25:56

标签: silverlight storyboard translate

我需要将这个xaml代码翻译成开头的代码。

            <Storyboard BeginTime="0:0:10" x:Name="sbEllipse1">
                <DoubleAnimation
                         Storyboard.TargetName="myBrush1"
                         Storyboard.TargetProperty="RadiusX"
                         From="0" To="1"
                         Duration="0:0:20"
                         />
                <DoubleAnimation
                         Storyboard.TargetName="myBrush1"
                         Storyboard.TargetProperty="RadiusY"
                         From="0" To="1"
                         Duration="0:0:20"
                          />
            </Storyboard>

2 个答案:

答案 0 :(得分:1)

Storyboard sb = new Storyboard();
sb.BeginTime = TimeSpan.FromSeconds(10);
sb.Children.Add(new DoubleAnimation());
sb.Children.Add(new DoubleAnimation());

答案 1 :(得分:1)

            Storyboard sb = new Storyboard();
            sb.BeginTime = TimeSpan.FromSeconds(10);

                    <DoubleAnimation
                     Storyboard.TargetName="myBrush1"
                     Storyboard.TargetProperty="RadiusX"
                     From="0" To="1"
                     Duration="0:0:20"
                     />
           //Equivalent code for the above is : 
            DoubleAnimation db = new DoubleAnimation();
            db.From = 0;
            db.To = 1;
            db.Duration = new Duration(TimeSpan.FromSeconds(20));
            Storyboard.SetTarget(db, myBrush1);
            Storyboard.SetTargetProperty(db, RadiusX);


                   <DoubleAnimation
                     Storyboard.TargetName="myBrush1"
                     Storyboard.TargetProperty="RadiusY"
                     From="0" To="1"
                     Duration="0:0:20"
                     />
           //Equivalent code for the above is :

            DoubleAnimation db1 = new DoubleAnimation();
            db1.From = 0;
            db1.To = 1;
            db1.Duration = new Duration(TimeSpan.FromSeconds(20));
            Storyboard.SetTarget(db, myBrush1);
            Storyboard.SetTargetProperty(db, RadiusY);
          //assigning both double animation to main Storyboard
            sb.Children.Add(db);
            sb.Children.Add(db1);
            myBrush1.Resources.Add(storyboard);
            sb.Begin();