WPF/Multithreading: UI Dispatcher in MVVM

前端 未结 7 1349
有刺的猬
有刺的猬 2020-12-24 09:49

So say in an MVVM environment, I\'m in a background thread and I\'d like to run an update on a ui control. So normally I\'d go myButton.Dispatcher.BeginInvoke(blabla) but I

7条回答
  •  情话喂你
    2020-12-24 10:16

    You could raise an event on your View Model (perhaps using a naming convention to indicate it's going to be raised from a non-UI thread - e.g. NotifyProgressChangedAsync). Then your View whom is attached to the event can deal with the dispatcher appropriately.

    Or, you could pass a delegate to a synchronizing function to your View Model (from your View).

提交回复
热议问题