WPF为gif效果旋转加载图像

我在wpf中有一个静态加载器图像,我可以通过使用WPFAnimatedGIF nuget包轻松地将它用作加载gif,但它看起来像是一种矫枉过正。

我的应用程序中只有一个场景,我想显示一个繁忙的指示器。

没有什么可以触发的,它是我窗口中隐藏的物体,在某些条件下它变得可见。 因此它应该始终旋转并显示为正常的动画加载gif。

到目前为止我尝试了什么

     

我正在使用的图像是

在此处输入图像描述

当Image元素可见时,此样式以30度为单位激活RotateTransform的角度。

  ...  

为了避免使用包含许多DiscreteDoubleKeyFrames的动画,您可以从DoubleAnimation派生并添加Step属性:

 public class DoubleAnimationWithSteps : DoubleAnimation { public static readonly DependencyProperty StepProperty = DependencyProperty.Register( nameof(Step), typeof(double), typeof(DoubleAnimationWithSteps)); public double Step { get { return (double)GetValue(StepProperty); } set { SetValue(StepProperty, value); } } protected override double GetCurrentValueCore( double from, double to, AnimationClock animationClock) { var value = base.GetCurrentValueCore(from, to, animationClock); if (Step > 0d) { value = Step * Math.Floor(value / Step); } return value; } protected override Freezable CreateInstanceCore() { return new DoubleAnimationWithSteps(); } } 

你会像这样使用它:

    

我知道这个问题已经有了答案,但有一种不同的方法。 只需使用ProgressBar并将IsIndeterminate设置为True:

  

样式来自XAML Toolkit中的Material Design 。 没有必要使用GIF作为忙碌指标,我前段时间犯了同样的错误