繁体   English   中英

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 reference") 程序立即崩溃并出现错误System.ArgumentException: '值不在预期范围内。'

我试图做的是对同一个控件使用多个表达式动画来同时更新不同的属性。

我的问题很简单,如何同时在同一个控件上执行多个表情动画,或者如何让一个表情动画运行多个表情并更新多个目标属性

这是我尝试执行的代码:

        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:我知道我可能可以使用向量作为位置并使用单个表达式,但我真正想要的是了解如何使用更多表达式来更新同一控件的多个目标值。

在此先感谢您的帮助!

如何同时在同一个控件上执行多个表情动画,

恐怕你不能像上面那样执行多个动画,这会使第二个动画无法使用第一个动画使用的控件。

对于执行多个表达式,我们建议您使用+ 组合在一起

例如

_parallaxExpression = compositor.CreateExpressionAnimation(
 "(ScrollManipulation.Translation.Y + StartOffset) * ParallaxValue - " +
"(ScrollManipulation.Translation.Y + StartOffset)");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM