GSI

세삼 느끼는 거지만 msdn의 예제는 너무 xaml 중심으로 되어 있다.
이런 코드의 예제가 절실하게 필요한 때인거 같다.

-- XAML CODE—

 

<Storyboard x:Key="OnCalendarLoaded">

 <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"

Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(SkewTransform.AngleX)"

Storyboard.TargetName="TargetShape">

                        <SplineDoubleKeyFrame   KeySpline="0.5,0.5,0.5,0.5" Value="0" KeyTime="00:00:00"/>

                        <SplineDoubleKeyFrame   KeySpline="0.5,0.5,0.5,0.5" Value="15" KeyTime="00:00:01"/>

            </DoubleAnimationUsingKeyFrames>

      </Storyboard>

….

          <Rectangle Stroke="White" Margin="0,20,0,0"

            Width="120" Height="100"

            x:Name="TargetShape"

            Fill="sc#0.400752217, 0.3677801, 0.3677801, 0.3677801">

              <Rectangle.RenderTransform>

                <TransformGroup>

                  <TranslateTransform X="0" Y="0"/>

                  <ScaleTransform ScaleX="0" ScaleY="0"/>

                  <SkewTransform AngleX="15" AngleY="0"/>

                  <RotateTransform Angle="0"/>

                  <TranslateTransform X="0" Y="0"/>

                  <TranslateTransform X="0" Y="0"/>

                </TransformGroup>

              </Rectangle.RenderTransform>

            </Rectangle>

 

Void StartAnimationsFunction()

{

      Storyboard story = (Storyboard)this.FindResource("OnCalendarLoaded");

      BeginStoryboard(story); // IT WORKS!

}

 


 

-- C# CODE --

 

<Storyboard x:Key="OnCalendarLoaded">

      </Storyboard>

 

 

Void StartAnimationsFunction ()

{

      Storyboard story = (Storyboard)this.FindResource("OnCalendarLoaded");

story.Children.Add(getAnimation1("TargetShape"));

      BeginStoryboard(story); // NOTHING HAPPENS!

}

       

        private DoubleAnimationUsingKeyFrames getAnimation1(string name)

        {

            DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();

            anim.BeginTime = new TimeSpan(0, 0, 0);

 

            Storyboard.SetTargetName(anim, name);

            Storyboard.SetTargetProperty(anim,

                new PropertyPath("0.1[2].2", new DependencyProperty[] {

                    UIElement.RenderTransformProperty,

                    TransformGroup.ChildrenProperty,

                    SkewTransform.AngleXProperty}));

 

            anim.KeyFrames.Add(new SplineDoubleKeyFrame(0, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0)), new KeySpline(.5, .5, .5, .5)));

            anim.KeyFrames.Add(new SplineDoubleKeyFrame(15, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 1)), new KeySpline(.5, .5, .5, .5)));

 

            return anim;

        }

Posted by gsi
: