我有一个 WPF 应用程序(称为启动器)并希望通过代码而不是通过 XAML 指定其他应用程序资源(例如其他视图、组件和内容)。此外,这些资源由第二个程序集定义(而不是定义的同一个程序集App.xaml
)
目前我们已经定义了这个App.xaml
:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/GUI;component/Common/ViewResources.xaml" />
<ResourceDictionary Source="/GUI;component/Common/ResourceDictionary.xaml" />
<ResourceDictionary Source="/Components;component/Common/ResourceDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
这行得通,但这不是我想要做的。为了解决这些资源,我需要在 URL 中指定程序集引用或在 EXE 中包含/复制资源(包含App.xaml
.)的程序集
有没有办法在代码的 GUI 端设置/初始化-应用程序资源?还有什么想法吗?
您必须假设 Launcher 已经进入“App::Run”,您必须在此事件发生后加载必要的 UI 资源,并且您必须保持在进程中。
有 3 个明显的解决方案是不可接受的:
在 GUI 中添加字典并将其合并到所有视图中(例如扩展现有 UI)
由于启动器已经是一个应用程序,我们不能在 GUI.Start 中做这样的事情(例如在进程中运行第二个应用程序):
公共无效开始(){应用程序=新应用程序();应用程序运行();}
两者(启动器和 GUI)都需要保持在同一个进程中,因此这样的解决方案是不可接受的(例如,在进程外启动第二个应用程序):
处理 myProc;myProc = Process.Start("GUI.exe");