ウィンドウのスタイルとテンプレート

このトピックでは、Window コントロールのスタイルとテンプレートについて説明します。 ControlTemplateの既定値を変更して外観を制御します。 詳細については、「コントロールのためにテンプレートを作成する」をご覧ください。

Window のパーツ

Window コントロールに名前付きパーツはありません。

Window の状態

次の表は、Window コントロールの表示状態の一覧を示します。

VisualState 名 VisualStateGroup 名 説明
有効 ValidationStates このコントロールで Validation クラスを使用し、Validation.HasError 添付プロパティは false です。
InvalidFocused ValidationStates Validation.HasError 添付プロパティは、コントロールにフォーカスがある true です。
InvalidUnfocused ValidationStates Validation.HasError 添付プロパティは、コントロールにフォーカスがない true です。

Window の ControlTemplate

次の例は、Window コントロールの既定のテンプレートをわずかに変更したコピーです。

<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>

関連項目