How to pass the UI Dispatcher to the ViewModel

前端 未结 16 649
独厮守ぢ
独厮守ぢ 2020-11-28 02:16

I\'m supposed to be able to access the Dispatcher that belongs to the View I need to pass it to the ViewModel. But the View should not know anything about the ViewModel, so

16条回答
  •  半阙折子戏
    2020-11-28 02:32

    You don't need to pass the UI Dispatcher to the ViewModel. The UI Dispatcher is available from the current application singleton.

    App.Current.MainWindow.Dispatcher
    

    This will make your ViewModel dependent on the View. Depending on your application, that may or may not be fine.

提交回复
热议问题