gpt4 book ai didi

c# - 倾斜动画无法动画

转载 作者:行者123 更新时间:2023-12-02 22:21:26 26 4
gpt4 key购买 nike

我在将倾斜动画转换为双重动画类方面取得了进展。剩下的唯一问题是当调度计时器调用动画时,会抛出一个错误。错误如下...

Cannot animate the 'AngleX' property on 'System.Windows.Media.MatrixTransform' because the object is sealed or frozen.

我将如何克服这个错误以使动画可以工作?

    public static void Grass(Canvas canvas, int boundry)
{
foreach (var element in canvas.Children.OfType<Image>())
{
if (element.Name == "GrassForeground" || element.Name == "GrassBackground")
{
var skewGrass = new DoubleAnimation
{
From = 0,
To = 10,
EasingFunction = new BackEase(),
AutoReverse = true
};
var transform = (MatrixTransform)element.RenderTransform;
transform.BeginAnimation(SkewTransform.AngleXProperty, skewGrass);
}
}
}

最佳答案

试试下面这个,或者你有特殊的理由使用 MatrixTransform?

public static void Grass(Canvas canvas, int boundry)
{
foreach (var element in canvas.Children.OfType<Image>())
{
if (element.Name == "GrassForeground" || element.Name == "GrassBackground")
{
var skewGrass = new DoubleAnimation
{
Duration = new Duration(TimeSpan.FromSeconds(5)),
From = 0,
To = 10,
EasingFunction = new BackEase(),
AutoReverse = true
};
element.RenderTransform = new SkewTransform();
element.RenderTransform.BeginAnimation(SkewTransform.AngleXProperty, skewGrass);
}
}
}

关于c# - 倾斜动画无法动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13673399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com