[英]How do I control a variable value from an ExpressionAnimation?
I'm using the AnimatedVisualPlayer within the Microsoft.UI.Xaml.Controls namespace.我在 Microsoft.UI.Xaml.Controls 命名空间中使用AnimatedVisualPlayer 。 I want the progress of the animation that is playing back to be available as a double so that I can update the value of progress slider.
我希望正在播放的动画的进度可以作为双精度使用,以便我可以更新进度滑块的值。
The AnimatedVisualPlayer provides a ProgressObject which is a Composition Object which you are supposed to bind to some property via an ExpressionAnimation . AnimatedVisualPlayer 提供了一个ProgressObject ,它是一个组合对象,您应该通过ExpressionAnimation将其绑定到某个属性。 Rather then using this object to drive another animation, I would like to have the animations progress available as a value.
与其使用此对象来驱动另一个动画,不如将动画进度作为值提供。 Is there any simple way to achieve this?
有什么简单的方法可以实现这一目标吗?
This is what I have tried so far:这是我迄今为止尝试过的:
internal void ProgressObjectToValue(CompositionObject ProgressObject)
{
var c = Window.Current.Compositor;
SpriteVisual targetVisual = c.CreateSpriteVisual();
ExpressionAnimation exp = c.CreateExpressionAnimation($"comp.Progress");
exp.SetReferenceParameter("comp", ProgressObject);
targetVisual.StartAnimation("Offset.X", exp);
double progressValue = targetVisual.Offset.X;
With this, it seems the targetVisuals offset is not bound to the AnimatedVisualPlayer's progress.有了这个,似乎 targetVisuals 偏移量不受 AnimatedVisualPlayer 的进度约束。 Thanks for any help you can provide!
感谢您的任何帮助,您可以提供!
I want the progress of the animation that is playing back to be available as a double so that I can update the value of progress slider.
我希望正在播放的动画的进度可以作为双精度使用,以便我可以更新进度滑块的值。
Derive from AnimatedVisualPlayer
TestUI project , we use the following to get progress value, during the testing, it always return 0 or 1 value.派生自
AnimatedVisualPlayer
TestUI 项目,我们使用以下方法获取进度值,在测试过程中,它始终返回 0 或 1 值。
var progressPropertySet = (CompositionPropertySet)Playback_Player.ProgressObject;
progressPropertySet.TryGetScalar("progress", out var value);
var progress = value.ToString();
For this scenario, we suggest you use timer to detect animation time, and use it to divide AnimatedVisualPlayer Duration
property to get progress.对于这种情况,我们建议您使用计时器来检测动画时间,并使用它来划分 AnimatedVisualPlayer
Duration
属性以获得进度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.