Reputation: 51
Im starting to get into some animations for some specific buttons, basically what im doing right now im struggling to find the proper way to insert multiple expression animations for the same control.
If i only call button1.StartAnimation("some expression animation reference") once, works as intended, however as soon as im trying to start a second animation button1.StartAnimation("a second expression animation reference") the program crashes imediately with error System.ArgumentException: 'Value does not fall within the expected range.'
What im trying to do is to use multiple expression animations for the same control to update different properties at the same time.
My question is simple, how can i execute multiple expression animations on the same control at the same time, OR how can i have an expression animation run multiple expressions and updating multiple target properties
Here is the code that im trying to execute:
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: I know i can probably use a vector for position and use a single expression but what i really want is to understand how can i use more expressions to update multiple target values for same control.
Thanks in advance for all your help!
Upvotes: 1
Views: 159
Reputation: 32775
how can i execute multiple expression animations on the same control at the same time,
I'm afraid you can't execute multiple animations like above that will make the second animation can't use the control that used by the first one.
For execute multiple expression, we suggest you use +
to combine together.
For example
_parallaxExpression = compositor.CreateExpressionAnimation(
"(ScrollManipulation.Translation.Y + StartOffset) * ParallaxValue - " +
"(ScrollManipulation.Translation.Y + StartOffset)");
Upvotes: 1