简体   繁体   中英

Doubleanimation Skew not working

I am trying to get this animation to work but for some reason nothing is happening when it is called by the Dispatch timer, any ideas?

    public static void Grass2(Canvas canvas, int boundry)
    {
        foreach (var element in canvas.Children.OfType<Image>())
        {
            var elementName = Regex.Split(element.Name, "_");
            if (elementName[0] == "grass")
            {
                var skewGrass = new DoubleAnimation
                    {
                        From = 0,
                        To = boundry,
                        Duration = new Duration(TimeSpan.FromMilliseconds(100)),
                        RepeatBehavior = RepeatBehavior.Forever,
                        EasingFunction = new BackEase(),
                        AutoReverse = true
                    };
                element.BeginAnimation(SkewTransform.AngleXProperty, skewGrass);
            }
        }
    }

You're trying to animate the SkewTransform.AngleXProperty on an object of type Image. That won't work since Image does not have this property. However, the Image's RenderTransform might be set to a SkewTransform, and that SkewTransform can be animated:

...
// each element's RenderTransform must be a SkewTransform
var transform = (SkewTransform)element.RenderTransform;
transform.BeginAnimation(SkewTransform.AngleXProperty, skewGrass);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM