【发布时间】:2021-12-24 23:56:41
【问题描述】:
我开始研究一些特定按钮的动画,基本上我现在正在做的事情是我正在努力寻找为同一控件插入多个表情动画的正确方法。
如果我只调用一次 button1.StartAnimation("some expression animation reference"),可以按预期工作,但是一旦我尝试启动第二个动画 button1.StartAnimation("a second expression animation reference") 程序就会崩溃立即出现错误 System.ArgumentException: 'Value does not fall in 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:我知道我可能可以使用向量作为位置并使用单个表达式,但我真正想要的是了解如何使用更多表达式来更新同一控件的多个目标值。
提前感谢您的帮助!
【问题讨论】:
标签: c# uwp winui-3 visual-studio-2022