【问题标题】:How do I control a variable value from an ExpressionAnimation?如何控制 ExpressionAnimation 中的变量值?
【发布时间】:2020-09-09 16:19:01
【问题描述】:

我在 Microsoft.UI.Xaml.Controls 命名空间中使用 AnimatedVisualPlayer。我希望正在播放的动画的进度可以作为双精度使用,以便我可以更新进度滑块的值。

AnimatedVisualPlayer 提供了一个ProgressObject,它是一个Composition Object,您应该通过ExpressionAnimation 绑定到某个属性。而不是使用这个对象来驱动另一个动画,我想让动画进度作为一个值可用。有什么简单的方法可以实现吗?

这是我迄今为止尝试过的:

 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;

这样看来,targetVisuals 偏移量并没有绑定到 AnimatedVisualPlayer 的进度。感谢您提供的任何帮助!

【问题讨论】:

    标签: c# xaml uwp uwp-xaml


    【解决方案1】:

    我希望正在播放的动画的进度以双精度形式提供,以便我可以更新进度滑块的值。

    从AnimatedVisualPlayerTestUIproject派生,我们使用以下获取进度值,在测试过程中,它总是返回0或1值。

    var progressPropertySet = (CompositionPropertySet)Playback_Player.ProgressObject;
    progressPropertySet.TryGetScalar("progress", out var value);
    var progress = value.ToString();
    

    对于这种情况,我们建议您使用计时器来检测动画时间,并使用它来划分AnimatedVisualPlayerDuration属性以获得进度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      相关资源
      最近更新 更多