Context:
I have a created a user control library project in Microsoft Visual Studio 2017 with a lot of Styles and ControlTemplates to be used in various future projects. Now I want to reference it in a new solution.
What works:
When I create a new solution with a new WPF-Application I can import the user control library project into the solution and add a reference to it in my new WPF-Application project - everything works fine this way. But this isn't a good solution for me because I don't want to copy the sourcecode everytime I use it.
What doesn't work:
...So I tried to not import it and referencing it as a project but to just reference the compiled dll-file of the user control library. In principle, everything should stay the same from the WPF-Applications point of view. But the Designer doesn't find the referenced resources correctly. At runtime it works perfectly well with no errors, but at designtime the Designer either ignores the referenced resources or crashes entirely.
Its behaviour doesn't seem to be very consistent anyway:
- It finds some resources correctly, e.g. It shows referenced ColorBrushes defined in the user control library correctly (e.g.
Background="{StaticResource MyBlue}"
) - Sometimes it seems to find a referenced Style-resource but not the resources nested within that Style (e.g.
Style="{StaticResource TextBoxOutput}"
shows error"The resource "MarginStandard" can't be found."
whenMarginStandard
is used inTextBoxOutput
) - Styles without a key which should apply by default don't apply automatically.
All this works correctly at runtime and when I reference the user control library as project rather than as dll.
What I already checked
- User control library and WPF-Application use the same CPU-Architecture (AnyCPU).
- User control library and WPF-Application use the same .net Version (4.6.1)
- I tried different Build-Actions for compiling the user control library (resource, embedded resource, none).
- The dll-file gets copied into the
bin/debug
-folder of the WPF-project. All resource dictionaries from the user control library are imported in the
App.xaml
file of the WPF-project using the following Syntax:<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/UserControlLibraryName;component/RecourceDictionaryName.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
My Question
How can I use resources referenced as dll-file in such a way that the Designer also finds the resources correctly? My Styles and ControlTemplates alter the look of the Controls drastically, so its really necessary to be able to see the results at designtime.