I have a CommonLibraryWpfThemes library with multiple XAML files in a resource dictionary. My Themes / Generic.xml contains a ResourceDictionary.MergedDictionaries declaration that combines all other files.
Generic.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
In my application project, I have a link to CommonLibraryWpfThemes, and I explicitly reference Generic.xml in my App.xaml file.
App.xaml - FAILS
<Application x:Class="MyApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /> </Application.Resources> </Application>
This does not work. When starting the application, the following error appears:
System.Windows.Markup.XamlParseException occurred Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive. Error at object 'System.Windows.Setter' in markup file 'CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml' Line 18 Position 13." Source="PresentationFramework" LineNumber=18 LinePosition=13
If I place the contents of Generic.xaml in App.xaml directly, everything works fine:
App.xaml - SUCCEEDS
<Application x:Class="MyApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" /> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
Perhaps I will change it wrong. My goal is to simplify the link to all my thematic resources from several applications without having to list all the individual files. Is there a recommended way to do this? (Note: I'm not trying to switch between multiple topics - I only have one topic.)
As a bonus, it would be nice if someone could tell me how to reference resources in an external library without breaking the constructor in Visual Studio.
Thank.
EDIT:
I tried to wrap a ResourceDictionary in a ResourceDictionary.MergedDictionary element, but this also did not work (I get the same error):
<Application x:Class="MyApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
wpf xaml themes resourcedictionary
devuxer Aug 04 '09 at 19:18 2009-08-04 19:18
source share