同一AppDomain中的多个WPF应用程序 [英] Multiple WPF applications in the same AppDomain

查看:51
本文介绍了同一AppDomain中的多个WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了以下设置:

WPF_Application.exe

WPF_Application.exe

包含WinForms窗口和WPF窗口的DLL.

a DLL that contains a WinForms Window and an WPF Window.

"WPF_Application.exe"从DLL调用WinForms窗口,而WinForms窗口在DLL中创建WPF窗口的实例.

The 'WPF_Application.exe' calls the WinForms window from the DLL and the WinForms Window creates an instance of the WPF window in the DLL.

这会产生以下异常:

在同一AppDomain中不能创建多个System.Windows.Application实例.

Cannot create more than one System.Windows.Application instance in the same AppDomain.

尝试了不同的方法,但不知道如何解决.

Tried different things, but couldn't figure out how to fix it.

推荐答案

我通过将wpf窗口的应用程序指派给Application.Current窗口来对其进行修复:

I fixed it by asigning the Application of the wpf window that is called to the Application.Current Window:

  if (Application.Current == null)
  {
       MyApplication = new Application
       {
          ShutdownMode = ShutdownMode.OnExplicitShutdown
       };
   }
   else
       MyApplication = Application.Current;

这篇关于同一AppDomain中的多个WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆