I have created a simple WPF custom control which inherits from Window, so that later I am able to override it's chrome and reuse it across my projects. The control is contained in its own project along with a generic.xaml file (in the Themes directory). The style for the control simply sets a red background. Within a second project (same solution) I then use the control as the base class of a new WPF window. When I now compile the project and have it run, it shows my (custom-)window with the desired red background.
My question is now: how do I get the WPF designer to show the generic style (in this case the red background) at design time?
When I do the same with, say, a button then the generic style is applied at design time automatically. But any default style of a control inheriting from Window will only show at runtime. What am I missing?
control code:
public class CustomControl1 : Window
{
static CustomControl1()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
}
}
generic.xaml:
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Border Background="Red"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The XAML of the test window in the second project where I use the control:
<snh:CustomControl1 x:Class="WpfDockWindow.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:snh="clr-namespace:SnH.WpfControls;assembly=SnH.WpfControls"
Title="TestWindow" Height="300" Width="300">
<Grid>
</Grid>
And for the records, I use VS2013 and the projects are compiled with framework 4.5.1.
Thx, Ben