Visual Studio/WPF > Resources/Style > x:Key를 지정하지 않는 Implicit key 예제

운영 환경
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community

XAML Resources

Styles, DataTemplates, and Implicit Keys
...
implicit key from the standpoint of requesting it is the 유형 of the control itself. The implicit key from the standpoint of defining the resource is the TargetType of the style.

Style에 관해서, x:Key를 지정하지 않고 TargetType으로 정의해 두면 Style을 변경할 수 있다는 것.

MainWindow.xaml
<Window x:Class="_170615_t1450_ImplicitKey.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_170615_t1450_ImplicitKey"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="Button">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush>
                        <GradientStop Offset="0.0" Color="AliceBlue"/>
                        <GradientStop Offset="1.0" Color="Salmon"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="18"/>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Button Width="100" Height="28" Content="Button1"/>
            <Button Width="100" Height="28" Content="Button2"/>
            <Button Width="100" Height="28" Content="Button3"/>
        </StackPanel>
    </Grid>
</Window>



관련 링크




스타일의 암시적 적용

좋은 웹페이지 즐겨찾기