How to pass the UI Dispatcher to the ViewModel

前端 未结 16 633
独厮守ぢ
独厮守ぢ 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:27

    Another common pattern (which is seeing much use now in the framework) is the SynchronizationContext.

    It enables you to dispatch synchronously and asynchronously. You can also set the current SynchronizationContext on the current thread, meaning it is easily mocked. The DispatcherSynchronizationContext is used by WPF apps. Other implementations of the SynchronizationContext are used by WCF and WF4.

提交回复
热议问题