How to pass the UI Dispatcher to the ViewModel

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

    for WPF and Windows store apps use:-

           System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => {ObservableCollectionMemeberOfVM.Add("xx"); } ));
    

    keeping reference to GUI dispatcher is not really the right way.

    if that doesn't work (such as in case of windows phone 8 apps) then use:-

           Deployment.Current.Dispatcher
    

提交回复
热议问题