My base assembly contains some xaml resources which are used by some custom WPF UserControl on assemblies which depend on this base dll, for this, I'm using
<ResourceDictionary Source="pack://application,,,/assemblyname;component/Resources.xaml"/>
I need to compile this base dll under different name. Since the assembly name is changing, this URI above get broken on other dll. I would like to use conditional compilation to change the assemblyname so I try to move the definition of the resource dictionary to the code behind doing something like
ResourceDictionary res = new();
res.Source=new Uri("/assemblyname;component/Resources.xaml", UriKind.Relative);
this.Resources.MergedDictionaries.Add(res);
the idea being to encapsulate this code in a #if ... #endif where the name of the assembly would change based on the compilation configuration. I'm not successful. Could someone provide an option to achieve this dynamic resource? Thanks
One solution which is working is eventually loading the resource in the App.xaml.cs so moving the code behind of my question from the constructor of the control to the App.xaml.cs and it solves the issue at runtime but then the control is not nice at design time. I found the solution of my problem using : moving uri to static member so then the issue is solved at runtime and design time