How to do a Translate Animation for both axis(X, Y) at the same time?

Posted by user1235555 on Stack Overflow See other posts from Stack Overflow or by user1235555
Published on 2012-03-15T14:44:47Z Indexed on 2012/03/22 11:29 UTC
Read the original article Hit count: 164

I am doing something like this in my Storyboard method but not able to achieve the desired result. This animation I want to be played after the page is loaded.

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        CreateTranslateAnimation(image1);
    }


        private void CreateTranslateAnimation(UIElement source)
        {
            Storyboard sb = new Storyboard();

            DoubleAnimationUsingKeyFrames animationFirstX = new DoubleAnimationUsingKeyFrames();
            source.RenderTransform = new CompositeTransform();
            Storyboard.SetTargetProperty(animationFirstX, new PropertyPath(CompositeTransform.TranslateXProperty));
            Storyboard.SetTarget(animationFirstX, source.RenderTransform);
            animationFirstX.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = kt1, Value = 20 });

            DoubleAnimationUsingKeyFrames animationFirstY = new DoubleAnimationUsingKeyFrames();
            source.RenderTransform = new CompositeTransform();
            Storyboard.SetTargetProperty(animationFirstY, new PropertyPath(CompositeTransform.TranslateYProperty));
            Storyboard.SetTarget(animationFirstY, source.RenderTransform);
            animationFirstY.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = kt1, Value = 30 });

    sb.Children.Add(animationFirstX);
            sb.Children.Add(animationFirstY);
            sb.Begin();             
         }

Too cut it short...

I want to write .cs code equivalent to this code

    <Storyboard x:Name="Storyboard1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="image1">
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="20"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="image1">
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="30"/>
        </DoubleAnimationUsingKeyFrames>
        </Storyboard>

© Stack Overflow or respective owner

Related posts about windows-phone-7

Related posts about animation