How to show a waitcursor when the WPF application is busy databinding

后端 未结 4 1335
眼角桃花
眼角桃花 2020-12-22 23:44

I have a WPF application using the MVVM pattern that sometimes have to show a waitcursor when it is busy doing something the user has to wait for. Thanks to a combination of

4条回答
  •  鱼传尺愫
    2020-12-23 00:43

    What I've done in the past is to define boolean properties in the viewmodel that indicates that a lengthy calculation is in progress. For instance IsBusy which is set to true when working and false when idle.

    Then in the view I bind to this and display a progress bar or spinner or similar while this property is true. I've personally never set the cursor using this approach but I don't see why it wouldn't be possible.

    If you want even more control and a simple boolean isn't enough, you can use the VisualStateManager which you drive from your viewmodel. With this approach you can in detail specify how the UI should look depending on the state of the viewmodel.

提交回复
热议问题