简体   繁体   English

View模型中的Catel显示对话窗口

[英]Catel show dialog window inside a ViewModel

Please Help. 请帮忙。 I put this construction in any method to main ViewModel 我以任何方法将此构造放入主ViewModel

Thread thread = new Thread(() =>
{
     _visualizerService.ShowDialog(new PurchaseWindowViewModel());
});

thread.SetApartmentState(ApartmentState.STA);
thread.Start();

And i have exception in PurchaseWindowViewModel.xaml.cs 而且我在PurchaseWindowViewModel.xaml.cs中有例外

An exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll but was not handled in user code. PresentationFramework.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理。 Additional information: Not access to object Freezable "Catel.Windows.Media.Effects.GrayscaleEffect" 附加信息:无法访问对象Freezable“ Catel.Windows.Media.Effects.GrayscaleEffect”

through the threads, as it can not be frozen. 通过线程,因为它不能被冻结。

Creating a window on a separate thread is hardly ever required and only "required" in edge-case scenarios. 几乎不需要在单独的线程上创建窗口,只有在极端情况下才需要“创建”窗口。 Please update your question why you want to use a window on a non-ui thread if the answer below does not solve your issue. 如果以下答案无法解决您的问题,请更新您的问题,为什么要在非UI线程上使用窗口。

I recommend that you use this code instead: 我建议您改用以下代码:

await _visualizerService.ShowDialogAsync<PurchaseWindowViewModel>();

or non async: 或非异步:

_visualizerService.ShowDialog<PurchaseWindowViewModel>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM