C# WinUI 项目,如何在同一个控件上添加多个 ExpressionAnimation?
C# WinUI project, How to add Multiple ExpressionAnimation on same control?
我开始研究一些特定按钮的动画,基本上我现在正在做的就是努力寻找为同一控件插入多个表达式动画的正确方法。
如果我只调用一次 button1.StartAnimation("some expression animation reference"),按预期工作,但是一旦我尝试启动第二个动画 button1.StartAnimation("a second expression animation参考”) 程序立即崩溃并出现错误 System.ArgumentException: 'Value does not fall within the expected range.'
我想做的是对同一个控件使用多个表达式动画来同时更新不同的属性。
我的问题很简单,我怎样才能同时在同一个控件上执行多个表达式动画,或者我怎样才能有一个表达式动画运行多个表达式并更新多个目标属性
这是我要执行的代码:
ExpressionAnimation anim1 = _compositor.CreateExpressionAnimation();
anim1.Expression = "-((self.Scale.X - 1) * (self.ActualSize.X * 0.01) * 50)";
anim1.Target = "Translation.X";
ExpressionAnimation anim2 = _compositor.CreateExpressionAnimation();
anim2.Expression = "-((self.Scale.Y - 1) * (self.ActualSize.Y * 0.01) * 50)";
anim2.Target = "Translation.Y";
anim1.SetExpressionReferenceParameter("self", button1);
anim2.SetExpressionReferenceParameter("self", button1);
button1.StartAnimation(anim1);//adds just fine and works as intended
button1.StartAnimation(anim2);//crashes instantly with error System.ArgumentException: 'Value does not fall within the expected range.'
PS:我知道我可能可以使用向量作为位置并使用单个表达式,但我真正想要的是了解如何使用更多表达式来更新同一控件的多个目标值。
在此先感谢您的帮助!
how can i execute multiple expression animations on the same control at the same time,
恐怕你不能像上面那样执行多个动画,这会使第二个动画无法使用第一个动画使用的控件。
执行多个表达式,建议使用+
至combine together。
例如
_parallaxExpression = compositor.CreateExpressionAnimation(
"(ScrollManipulation.Translation.Y + StartOffset) * ParallaxValue - " +
"(ScrollManipulation.Translation.Y + StartOffset)");
我开始研究一些特定按钮的动画,基本上我现在正在做的就是努力寻找为同一控件插入多个表达式动画的正确方法。
如果我只调用一次 button1.StartAnimation("some expression animation reference"),按预期工作,但是一旦我尝试启动第二个动画 button1.StartAnimation("a second expression animation参考”) 程序立即崩溃并出现错误 System.ArgumentException: 'Value does not fall within the expected range.'
我想做的是对同一个控件使用多个表达式动画来同时更新不同的属性。
我的问题很简单,我怎样才能同时在同一个控件上执行多个表达式动画,或者我怎样才能有一个表达式动画运行多个表达式并更新多个目标属性
这是我要执行的代码:
ExpressionAnimation anim1 = _compositor.CreateExpressionAnimation();
anim1.Expression = "-((self.Scale.X - 1) * (self.ActualSize.X * 0.01) * 50)";
anim1.Target = "Translation.X";
ExpressionAnimation anim2 = _compositor.CreateExpressionAnimation();
anim2.Expression = "-((self.Scale.Y - 1) * (self.ActualSize.Y * 0.01) * 50)";
anim2.Target = "Translation.Y";
anim1.SetExpressionReferenceParameter("self", button1);
anim2.SetExpressionReferenceParameter("self", button1);
button1.StartAnimation(anim1);//adds just fine and works as intended
button1.StartAnimation(anim2);//crashes instantly with error System.ArgumentException: 'Value does not fall within the expected range.'
PS:我知道我可能可以使用向量作为位置并使用单个表达式,但我真正想要的是了解如何使用更多表达式来更新同一控件的多个目标值。
在此先感谢您的帮助!
how can i execute multiple expression animations on the same control at the same time,
恐怕你不能像上面那样执行多个动画,这会使第二个动画无法使用第一个动画使用的控件。
执行多个表达式,建议使用+
至combine together。
例如
_parallaxExpression = compositor.CreateExpressionAnimation(
"(ScrollManipulation.Translation.Y + StartOffset) * ParallaxValue - " +
"(ScrollManipulation.Translation.Y + StartOffset)");