I have a WPF application (call it a Launcher) and wish to specify additional application resources (such as additional Views, Components and Content) via Code, not via XAML. Further, these resources are defined by a second assembly (and not the same assembly which defines App.xaml
)
Currently we have this defined in 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>
This works, but it's not what I am attempting to do. For these resources to resolve I need to specify an assembly reference in the URL or include/duplicate the resources in the EXE (the assembly containing App.xaml
.)
Is there a way to set/initialize -application resources- in GUI side in code? Any other idea?
You must assume the Launcher will have already entered "App::Run", you must load the necessary UI resources after this event occurs, and you must remain in-process.
There are 3 obvious solutions which are not acceptable:
Add a Dictionary in GUI and Merge it in all Views (e.g. extend an existing UI)
Since the Launcher is already an Application we can't do something like this in GUI.Start (e.g. run a second App in-process):
public void Start() { App app = new App(); app.Run(); }
Both (Launcher and GUI) need to stay in the same process, so a solution like this is not acceptable (e.g. launch a second App out-of-process):
Process myProc; myProc = Process.Start("GUI.exe");
A colleague just came up with a solution, and its simple actually:
Providing a property GUI.Resources, used to set all Launcher App Resources:
Then call it in App.xaml.cs of the Launcher: