本文介绍了DoubleAnimation是歪斜不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让这个动画的工作,但由于某种原因,什么也没有发生,当它被调度计时器叫,任何想法?
公共静态无效Grass2(帆布油画,诠释疆)
{
的foreach()(在canvas.Children.OfType&LT VAR元素;图片&GT)
{
VAR的ElementName = Regex.Split(element.Name,_);
如果(的ElementName [0] ==草)
{
VAR skewGrass =新DoubleAnimation是
{
从= 0,
为了=疆,
持续时间=新的持续时间(TimeSpan.FromMilliseconds(100)),
的repeatBehavior = RepeatBehavior.Forever,
的easingFunction =新BackEase()
自动翻转=真
};
element.BeginAnimation(SkewTransform.AngleXProperty,skewGrass);
}
}
}
解决方案
您正试图动画 SkewTransform.AngleXProperty
输入图像的对象。这是行不通的,因为图像没有这个属性。但是,图像的的RenderTransform
可能被设置为一个SkewTransform,那SkewTransform可以设置动画:
...
//每个元素的的RenderTransform必须是SkewTransform
VAR变换=(SkewTransform)element.RenderTransform;
transform.BeginAnimation(SkewTransform.AngleXProperty,skewGrass);
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);
这篇关于DoubleAnimation是歪斜不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!