■ Style 엘리먼트 : 클래스 계층과 일치하는 스타일 계층 사용하기

----------------------------------------------------------------------------------------------------

<StackPanel

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

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

    <StackPanel.Resources>

        <Style TargetType="{x:Type Control}">

            <Setter Property="Control.FontSize"            Value="24"     />

            <Setter Property="Control.Foreground"          Value="Blue"   />

            <Setter Property="Control.HorizontalAlignment" Value="Center" />

            <Setter Property="Control.Margin"              Value="24"     />

        </Style>

        <Style

            TargetType="{x:Type Button}"

            BasedOn="{StaticResource {x:Type Control}}">

            <Setter Property="Control.Foreground" Value="Red" />

        </Style>

        <Style

            TargetType="{x:Type Label}"

            BasedOn="{StaticResource {x:Type Control}}">

            <Setter Property="Control.Foreground" Value="Green" />

        </Style>

        <Style

            TargetType="{x:Type TextBox}"

            BasedOn="{StaticResource {x:Type Control}}">

        </Style>

    </StackPanel.Resources>

    <Button>Button 컨트롤</Button>

    <Label>Label 컨트롤</Label>

    <TextBox>TextBox 컨트롤</TextBox>

</StackPanel>

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG