WPF Animation on Projection Property using code or XAML

WPF Animation on Projection Property using code or XAML

If you try to define DoubleAnimation on Projection property then you will see lot of challenge. Here is How to fix.

First make sure you create Name Attribute on Projection property like below for whatever UI element you want animate. So in below Example If I want to change Projection of Image then I will need Name for Image.Projection


                <Image Margin="11" Name="Image1" Source="/Assets/Images/Tile_Fruits.png" Height="200" >
                    <Image.Projection>
                        <PlaneProjection x:Name="Image1Projection" RotationX="0" RotationY="0" RotationZ="0"  />
                    </Image.Projection>
                </Image>

If you using C# code to create Storyboard then try this code

        public static void FlipImage(Image img)
        {

            Storyboard _storyBoard = new Storyboard();
            DoubleAnimation animation = new DoubleAnimation()
            {
                From = 0,
                Duration = new Duration(TimeSpan.FromSeconds(2)),
                To = 60,
            };
            Storyboard.SetTarget(animation, img);
            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
            _storyBoard.Children.Add(animation);
            _storyBoard.Begin();

            return;
        }

Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.

Leave a Reply