How can I stop the WPF ProgressBar pulsing/animating when it reaches 100%?

后端 未结 5 976
心在旅途
心在旅途 2021-02-05 03:52

I have an MVVM-based WPF 4 application which uses a ProgressBar to show the percentage completion of a long-running operation.



        
5条回答
  •  你的背包
    2021-02-05 04:06

    Dabblernl's answer is robust. Here is a hack (because it relies on the internal name of the element that does the glow, which is an implementation detail and may change in a subsequent version):

    void SetGlowVisibility(ProgressBar progressBar, Visibility visibility) {
        var anim = progressBar.Template.FindName("Animation", progressBar) as FrameworkElement;
        if (anim != null)
            anim.Visibility = visibility;
    }
    

    If how a ProgressBar is implemented changes, this hack may stop working.

    On the other hand, a solution that completely replaces the XAML and styles may lock-in and fix colours, borders etc. and disable behaviour that might be added to a newer version of the ProgressBar in the future...

    Edit: The implementation detail did change. Changed "PART_GlowRect" to "Animation" -- the former is used only in aero.normalcolor.xaml, while the latter is used in more recent aero2.normalcolor.xaml and aerolite.normalcolor.xaml too.

提交回复
热议问题