更新时间:2023-11-13 23:07:34
好吧,实际上ElementHost在其中显示了整个WPF应用程序.
我认为,它不允许您从外部(winforms appliction)更新诸如ContentPresenter之类的控件.
我认为公开一种方法可以为您创建ContentPresenter是一个好习惯.
Sacha Barbar提出了一个很好的扩展,可以处理跨线程问题.您可以看一下.
检查一下:
Well, actually ElementHost displays the whole WPF app within it.
I think, it does not allow you to update controls like ContentPresenter from outside(winforms appliction).
I think it would be a good practice to expose one method which will create this ContentPresenter for you.
Sacha Barbar proposed a good extension to work with Cross thread issues. You might take a look into it.
Check this :
public static void InvokeIfRequired(this DispatcherControl control, Action operation)
{
if (control.Dispatcher.CheckAccess())
{
operation();
}
else
{
control.Dispatcher.BeginInvoke(DispatcherPriority.Normal, operation);
}
}