DoubleAnimation是歪斜不工作(Doubleanimation Skew not wor

2019-11-01 06:03发布

我试图让这个动画的工作,但由于某种原因,没有什么是当它被调度计时器叫发生的事情,任何想法?

    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);
            }
        }
    }

Answer 1:

你试图动画SkewTransform.AngleXProperty Image类型的对象。 这是行不通的,因为图像没有这个属性。 但是,图像的RenderTransform可能被设置为一个SkewTransform,并SkewTransform可以是动态的:

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


文章来源: Doubleanimation Skew not working
标签: c# wpf animation