첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

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

 

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

Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요