첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ Trigger 엘리먼트를 사용해 버튼 클릭시 배경색을 변경하는 방법을 보여준다.

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="Trigger 엘리먼트 : 버튼 클릭시 배경색 변경하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button
            Width="300"
            Height="200"
            HorizontalContentAlignment="Center"
            VerticalContentAlignment="Center"
            FontSize="32"
            FontWeight="Bold"
            Foreground="White">
            테스트 버튼
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Background="{TemplateBinding Background}">
                        <ContentPresenter
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                </ControlTemplate>
            </Button.Template>
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Background" Value="Blue" />
                    <Style.Triggers>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" Value="Red" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
    </Grid>
</Window>
728x90
그리드형(광고전용)
Posted by icodebroker
,