I have created custom window classes for dialogs like this:
public class DialogBase : Window
{
// common stuff here
}
public class DialogOkCancel : DialogBase
{
static DialogOkCancel()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogOkCancel),
new FrameworkPropertyMetadata(typeof(DialogOkCancel)));
}
// specific stuff here
}
The styles looks like this, and contains dialog specific things such as title bar, OK/Cancel buttons etc.
<Style x:Key="DialogBaseStyle" TargetType="{x:Type base:DialogBase}" BasedOn="{StaticResource {x:Type Window}}">
<Setter Property="ShowInTaskbar" Value="False"/>
<!-- more stuff here -->
</Style>
<Style TargetType="{x:Type base:DialogOkCancel}" BasedOn="{StaticResource DialogBaseStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type base:DialogOkCancel}">
<!-- more stuff here -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This works perfectly fine during runtime. Also, the dialogs displays fine in XAML Designer.
However, in XAML Designer, the DialogOkCancel
style gets applied to other all other windows as well, such as the application main window (which simply derives from plain Window
). The title bar, buttons and everything. I don't really get this, as the TargetType
is specific. This does not occur at runtime.
What am I not seeing here ?