I've implemented a Shared Resources Dictionary, the app is compiled and run without problems but the XAML designer doesn't render the liked resources by its.
The designer report the follow issues over the "Source" property:
cannot create unknown type {clr-namespace:[namespaces'object...]}.SharedResourceDictionary
I have tried to move to another namespace, to "application root" and add property decency to Source field.
I'm using WPF framework, C#, Visual Studio 2017 version 15.9.5
Have i forget something to object?
The SharedResourceDictionarys' code is the follow:
public class SharedResourceDictionary : ResourceDictionary
{
private Uri _sourceUri;
private static readonly Dictionary<Uri, ResourceDictionary> SharedDictionaries = new Dictionary<Uri, ResourceDictionary>();
public new Uri Source
{
get => _sourceUri;
set
{
_sourceUri = value;
if (!SharedDictionaries.ContainsKey(value))
{
base.Source = value;
SharedDictionaries.Add(value, this);
}
else
{
MergedDictionaries.Add(SharedDictionaries[value]);
}
}
}
}
Edited:
I have discovered at this answer the problem is caused by
base.Source = value;
I have wrapped it at try catch like suggested by the answer and the designer doesn't report issue anymore but it doesn't render the views.
I've partially fixed it wrapping the "Source" property with preprocessor directives "Release" but whether i need a memory test in debug i could comment it.
I've also tried another answer but only some resources is imported and i don't have understand why.
Edited:
I've reported this issue on Visual Studio Community but i have fixed with #debug and #release directive like the follow example
public class SharedResourceDictionary : ResourceDictionary
{
#if RELEASE
private Uri _sourceUri;
private static readonly Dictionary<Uri, ResourceDictionary> SharedDictionaries =
new Dictionary<Uri, ResourceDictionary>();
public new Uri Source
{
get => _sourceUri;
set
{
_sourceUri = value;
if (!SharedDictionaries.ContainsKey(value))
{
base.Source = value;
SharedDictionaries.Add(value, this);
}
else
{
MergedDictionaries.Add(SharedDictionaries[value]);
}
}
}
#endif
}