WPF跟WinForm在这一点上是相同的:简单点来讲就是——刷新界面的活只能在UI线程里跑。你的问题是:你试图在另一个线成里刷新UI,这时候错误就会抛出,因为非UI线程是不能亲自刷新UI的,它们需要告诉UI线程:“我们需要你帮助把UI刷新一下”。

如果你是在.xaml.cs文件中,你可以直接调用Dispatcher.Invoke((Action)delegate { /* Your
code is put here */ });

如果你在ViewModel里,你可以Application.Current.Dispatcher.Invoke((Action)delegate { /* Your code is put here */ });

相关文章:

  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-02-07
  • 2021-09-21
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2021-07-26
  • 2021-07-27
  • 2021-08-02
  • 2021-10-15
  • 2021-05-15
  • 2022-01-24
相关资源
相似解决方案