WPF

04. 버튼 테마

HicKee 2023. 3. 1. 23:36

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style BasedOn="{StaticResource {x:Type ToggleButton}}"
           TargetType="{x:Type RadioButton}"
           x:Key="MenuButtonTheme">
        <Style.Setters>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <Grid VerticalAlignment="Stretch"
                              HorizontalAlignment="Stretch"
                              Background="{TemplateBinding Background}">
                            
                            <TextBlock Text="{TemplateBinding Property=Content}"
                                       VerticalAlignment="Center"
                                       Margin="50,0,0,0"/>
                            
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>

            </Setter>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
        </Style.Setters>

        <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Background" Value="#22202f"/>
            </Trigger>
        </Style.Triggers>
        <!--실제로 사용하기 위해서는 App.xaml로 이동하여 추가적인 작업이 필요하다-->
    </Style>
    
</ResourceDictionary>

'WPF' 카테고리의 다른 글

03. column, row 설정  (0) 2023.02.26
02. Image 이미지  (0) 2023.02.25
01. StackPanel  (0) 2023.02.21