Changing the cursor in WPF sometimes works, sometimes doesn't

后端 未结 5 616
[愿得一人]
[愿得一人] 2020-11-28 23:08

On several of my usercontrols, I change the cursor by using

this.Cursor = Cursors.Wait;

when I click on something.

Now I want to do

5条回答
  •  离开以前
    2020-11-28 23:40

    You can use a data trigger (with a view model) on the button to enable a wait cursor.

    
    

    Here is the code from the view-model:

    public class MainViewModel : ViewModelBase
    {
       // most code removed for this example
    
       public MainViewModel()
       {
          GoCommand = new DelegateCommand(OnGoCommand, CanGoCommand);
       }
    
       // flag used by data binding trigger
       private bool _isWorking = false;
       public bool IsWorking
       {
          get { return _isWorking; }
          set
          {
             _isWorking = value;
             OnPropertyChanged("IsWorking");
          }
       }
    
       // button click event gets processed here
       public ICommand GoCommand { get; private set; }
       private void OnGoCommand(object obj)
       {
          if ( _selectedCustomer != null )
          {
             // wait cursor ON
             IsWorking = true;
             _ds = OrdersManager.LoadToDataSet(_selectedCustomer.ID);
             OnPropertyChanged("GridData");
    
             // wait cursor off
             IsWorking = false;
          }
       }
    }
    
        

    提交回复
    热议问题