简体   繁体   English

如何从 ExpressionAnimation 控制变量值?

[英]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.

相关问题 C# WinUI 项目,如何在同一个控件上添加多个 ExpressionAnimation? - C# WinUI project, How to add Multiple ExpressionAnimation on same control? 我如何从Literall Control ASP NET获得价值 - How do i get a value from Literall Control ASP NET 我如何将值从用户控件传递到另一个用户控件 - How do i pass value from User Control to another User Control 如何创建变量并从数据库访问值? - How do I create variable and accessing value from database? 如何从其他控件中清除asp:textbox控件? - How do I clear an asp:textbox control from a different control? 如何从内置字符串(控件名称)访问控件? - How do I access a control from a built string(control name)? XNA:如何更改另一个类的变量值? - XNA: How do I change a variable value from another class? 如何访问控件类型变量的可能属性? - How do I access a Control type variable's possible properties? 从一个视图切换到另一个视图时,如何保持用户控件的 Textbox Text 属性的值? - How do I persist the value of the Textbox Text property of a user control when switching from one view to another? 如何将值从一种形式传递给另一种形式的变量,而该变量实际上改变了变量的默认值? - How do I pass a value from one form to a variable in another that actually changes the default value of the variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM