I have used a custom class to implement shared resource functionality in my WPF application this is a sample code to create and manage dictionaries
public class SharedResourceDictionary : ResourceDictionary
{
/// <summary>
/// Internal cache of loaded dictionaries
/// </summary>
public static Dictionary<Uri, ResourceDictionary> SharedDictinaries = new Dictionary<Uri, ResourceDictionary>();
/// <summary>
/// Local member of the source uri
/// </summary>
private Uri _sourceUri;
private static bool IsInDesignMode
{
get
{
return (bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty,
typeof(DependencyObject)).Metadata.DefaultValue;
}
}
/// <summary>
/// Gets or sets the uniform resource identifier (URI) to load resources from.
/// </summary>
public new Uri Source
{
get
{
if (IsInDesignMode)
{
return base.Source;
}
return _sourceUri;
}
set
{
if (!IsInDesignMode)
{
base.Source = value;
return;
}
_sourceUri = value;
if (!SharedDictinaries.ContainsKey(value))
{
base.Source = value;
SharedDictinaries.Add(value, this);
}
else
{
MergedDictionaries.Add(SharedDictinaries[value]);
}
}
}
}
this File is implemented i a separate assembly and I have refferenced it in my shell WPF application.
I have my resources defined in app.xaml int the following way
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<Infrastructure:SharedResourceDictionary Source="pack://application:,,,/CuratioCMS.Client.Resources;Component/Themes/General/Brushes.xaml" />
<Infrastructure:SharedResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
if I remove Brushes.xaml it works but with this dictinary in place as I switch to design view I get following error
Exception has been thrown by the target of an invocation
could someone help my to figure out the problem?