Check the following scenario (others may apply as well) [you can create the project just copy pasting the code here on the right file]:
a - Create a ResourceDictionary with basic stuff (Resources.xaml):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush Color="Red" x:Key="Test" />
<Style TargetType="{x:Type GroupBox}" x:Key="Test2" >
<Setter Property="Background" Value="Blue" />
</Style>
<Style TargetType="{x:Type TextBlock}" >
<Setter Property="Foreground" Value="Green" />
</Style>
</ResourceDictionary>
b - Create a user control base where others will inherit containing basic resources (UserControlBase.cs):
using System.Windows.Controls;
using System;
using System.Windows;
namespace ResourceTest
{
public class UserControlBase : UserControl
{
public UserControlBase()
{
this.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("ResourceTest;component/Resources.xaml", UriKind.RelativeOrAbsolute) });
}
}
}
c - Create a UserControl inheriting from the base (UserControl1.xaml):
<ResourceTest:UserControlBase x:Class="ResourceTest.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ResourceTest="clr-namespace:ResourceTest"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300" >
<Grid>
<GroupBox BorderBrush="{StaticResource Test}" Margin="3" Header="Test" Style="{DynamicResource Test2}" >
<TextBlock Text="TESTTEST" />
</GroupBox>
</Grid>
</ResourceTest:UserControlBase>
Results: StaticResources are not resolved (and the Test BorderBrush is not loaded). DynamicResources are resolved (the background is blue) but the designer says that it cannot find the resource anyway (the first time works ok but when you open/close the designer the resource cannot be resolved). Non named resources like the TextBlock style work ok.
Is this a designer bug or am I doing something wrong? Is ok to have to declare the resources as dynamic in an scenario where the resources will never change?
Thanks in advance.