728x90
728x170

Style.Triggers 를 이용하여 Control 에 액션을 취한경우 어떠한 처리를 할 수 있습니다.

아래 예시는 Button, Label 에 마우스를 올렸을때 글자가 파란색으로 굵게 나타도록 한 것입니다.

Button 은 클릭시 글자 색을 변경합니다.

 

<Window x:Class="WpfApp3.MainWindow"

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

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

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

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <StackPanel>

        <StackPanel.Resources>

            <Style

                x:Key="normal">

                <Setter

                    Property="Control.FontSize"

                    Value="20" />

                <Setter

                    Property="Control.HorizontalAlignment"

                    Value="Center" />

                <Style.Triggers>

                    <Trigger

                        Property="Control.IsMouseOver"

                        Value="true">

                        <Setter

                            Property="Control.FontWeight"

                            Value="Bold" />

                        <Setter

                            Property="Control.Foreground"

                            Value="Blue" />

                    </Trigger>

                    <Trigger

                        Property="Button.IsPressed"

                        Value="true">

                        <Setter

                            Property="Control.Foreground"

                            Value="Red" />

                    </Trigger>

                </Style.Triggers>

            </Style>

        </StackPanel.Resources>

        <Button Style="{StaticResource normal}" Content="Test Button"/>

        <Label Style="{StaticResource normal}" Content="Test Label"/>

    </StackPanel>

</Window>

 

 

 

* MouseOver

  >     >

 

* Button Click

 

728x90
그리드형
Posted by kjun
,