Martin Freitag
Martin Freitag

Reputation: 11

Correct Property Path for Width-Animation in Windows Store Apps (Windows 8.1 and above)

I don't understand why my Canvas.Left and Canvas.Top Animations are running, but my Width and Height Animations are not.

Here is one example of perfectly working code:

                DoubleAnimation doubleAnimationCanvasLeft = new DoubleAnimation();
                doubleAnimationCanvasLeft.From = Canvas.GetLeft(aDiceToBeChecked.myGrid);
                doubleAnimationCanvasLeft.To = Canvas.GetLeft(aDiceToBeChecked.myGrid) - 102;
                doubleAnimationCanvasLeft.Duration = TimeSpan.FromMilliseconds(myTimespan);
                doubleAnimationCanvasLeft.FillBehavior = FillBehavior.HoldEnd;

                Storyboard storyboardCanvasLeft = new Storyboard();
                storyboardCanvasLeft.Children.Add(doubleAnimationCanvasLeft);

                Storyboard.SetTarget(storyboardCanvasLeft, aDiceToBeChecked.myGrid);
                Storyboard.SetTargetProperty(storyboardCanvasLeft, "(Canvas.Left)");
                storyboardCanvasLeft.Begin();

And the same for width does not work:

                DoubleAnimation doubleAnimationGridWidth = new DoubleAnimation();
                doubleAnimationGridWidth.From = 200.0;
                doubleAnimationGridWidth.To = 304.0;
                doubleAnimationGridWidth.Duration = TimeSpan.FromMilliseconds(myTimespan);
                doubleAnimationGridWidth.FillBehavior = FillBehavior.HoldEnd;

                Storyboard storyboardGridWidth = new Storyboard();
                storyboardGridWidth.Children.Add(doubleAnimationGridWidth);

                Storyboard.SetTarget(storyboardGridWidth, aDiceToBeChecked.myGrid);
                Storyboard.SetTargetProperty(storyboardGridWidth, "(Width)");
                storyboardGridWidth.Begin();

It does not work with Width, (Width), (UIElement.Width), (Grid.Width) and I am really not sure how to get the correct Property Path of if the Property Path is even the problem!? Could you help me?

I am using Net Version 4.5.1 and Visual Studio Express 2013 and developing for Windows 8.1 and Windows 10.

Upvotes: 0

Views: 86

Answers (1)

Martin Freitag
Martin Freitag

Reputation: 11

I found the missing piece:

                doubleAnimationGridWidth.EnableDependentAnimation = true;

If someone else is reading this: This means this animation is using more ressources of the UI Thread. There is more information on the Microsoft-Website.

Still, if someone could tell me how to build and or debug these property paths...

Upvotes: 1

Related Questions