display Hourglass when application is busy

前端 未结 9 1673
说谎
说谎 2020-11-28 03:01

For a view constructed using WPF, I want to change the mouse cursor to a hourglass when the application is busy and nonresponsive.

One solution is to add



        
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:42

    We did a disposable class that changes the cursor for us when the app is going to take long, it looks like this:

    public class WaitCursor : IDisposable
    {
        private Cursor _previousCursor;
    
        public WaitCursor()
        {
            _previousCursor = Mouse.OverrideCursor;
    
            Mouse.OverrideCursor = Cursors.Wait;
        }
    
        #region IDisposable Members
    
        public void Dispose()
        {
            Mouse.OverrideCursor = _previousCursor;
        }
    
        #endregion
    }
    

    And we use it like this:

    using(new WaitCursor())
    {
        // very long task
    }
    

    Might not be the greatest design, but it does the trick =)

提交回复
热议问题