WPF loading spinner

后端 未结 14 864
我寻月下人不归
我寻月下人不归 2020-12-02 05:30

The goal is to display the information that the application is working. So I\'m looking for an intelligent implementation sample of a loading spinner using WPF / MVVM.

14条回答
  •  感动是毒
    2020-12-02 06:14

    CircularProgressBarBlue.xaml

    
    
        
            
        
    
    
        
            
                
            
        
    
    
    
    

    CircularProgressBarBlue.xaml.cs

    using System;
    
    using System.Windows;
    
    using System.Windows.Media.Animation;
    
    
            /// 
        /// Interaction logic for CircularProgressBarBlue.xaml
        /// 
        public partial class CircularProgressBarBlue
        {
            private Storyboard _sb;
    
            public CircularProgressBarBlue()
            {
                InitializeComponent();
                StartStoryBoard();
                IsVisibleChanged += CircularProgressBarBlueIsVisibleChanged;
            }
    
            void CircularProgressBarBlueIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                if (_sb == null) return;
                if (e != null && e.NewValue != null && (((bool)e.NewValue)))
                {
                    _sb.Begin();
                    _sb.Resume();
                }
                else
                {
                    _sb.Stop();
                }
            }
    
            void StartStoryBoard()
            {
                try
                {
                    _sb = (Storyboard)TryFindResource("spinning");
                    if (_sb != null)
                        _sb.Begin();
                }
                catch
                { }
            }
        }
    

提交回复
热议问题