WPF /多线程:UI调度中MVVM [英] WPF/Multithreading: UI Dispatcher in MVVM
问题描述
所以在MVVM环境说,我在后台线程,我想上运行UI控件更新。所以通常我会去myButton.Dispatcher.BeginInvoke(布拉布拉),但我没有访问myButton的(因为视图模型不具有访问视图控件)。那么,什么是这样做的正常模式?
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 don't have access to myButton (because the viewmodel doesn't have access to the view's controls). So what is the normal pattern for doing this?
(我想总会有约束力,但我想知道如何通过调度做)
(I guess there's always binding, but I'd like to know how to do it via the dispatcher)
推荐答案
我通常使用 Application.Current.Dispatcher
:因为 Application.Current
是静态的,你不需要参照控制
I usually use Application.Current.Dispatcher
: since Application.Current
is static, you don't need a reference to a control
这篇关于WPF /多线程:UI调度中MVVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!