Window Styles and Templates

This topic describes the styles and templates for the Window control. You can modify the default ControlTemplate to give the control a unique appearance. For more information, see Create a template for a control.

Window Parts

The Window control does not have any named parts.

Window States

The following table lists the visual states for the Window control.

VisualState Name VisualStateGroup Name Description
Valid ValidationStates The control uses the Validation class and the Validation.HasError attached property is false.
InvalidFocused ValidationStates The Validation.HasError attached property is true has the control has focus.
InvalidUnfocused ValidationStates The Validation.HasError attached property is true has the control does not have focus.

Window ControlTemplate

The following example is a slightly modified copy of the default template for a Window control:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="WindowStyle1" TargetType="{x:Type Window}">
        <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
        <Setter Property="Background"
                Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <AdornerDecorator>
                            <ContentPresenter/>
                        </AdornerDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Window.ResizeMode"
                     Value="CanResizeWithGrip">
                <Setter Property="Template"
                        Value="{StaticResource WindowTemplateKey}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>

See also