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

■ TextBox 엘리먼트의 Text 속성 변경시 애니메이션을 사용하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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="TextBox 엘리먼트 : Text 속성 변경시 애니메이션 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid.Resources>
            <SolidColorBrush x:Key="BlackSolidColorBrushKey" Color="Black" />
            <SolidColorBrush x:Key="WhiteSolidColorBrushKey" Color="White" />
        </Grid.Resources>
        <TextBox
            Width="150"
            Height="25"
            VerticalContentAlignment="Center">
            <TextBox.Effect>
                <DropShadowEffect
                    BlurRadius="0"
                    ShadowDepth="0"
                    Opacity="0"
                    Color="White" />
            </TextBox.Effect>
            <TextBox.Style>
                <Style TargetType="TextBox">
                    <Style.Triggers>
                        <EventTrigger RoutedEvent="TextChanged">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ThicknessAnimation
                                            Storyboard.TargetProperty="BorderThickness"
                                            AutoReverse="True"
                                            Duration="00:00:02"
                                            From="1"
                                            To="2" />
                                        <DoubleAnimation
                                            Storyboard.TargetProperty="Effect.Opacity"
                                            To="1" />
                                        <ColorAnimation
                                            Storyboard.TargetProperty="Effect.Color"
                                            RepeatBehavior="2x"
                                            AutoReverse="True"
                                            Duration="00:00:02"
                                            From="Red"
                                            To="Purple" />
                                        <DoubleAnimation
                                            Storyboard.TargetProperty="Effect.ShadowDepth"
                                            RepeatBehavior="2x"
                                            AutoReverse="True"
                                            Duration="00:00:02"
                                            From="0"
                                            To="1" />
                                        <DoubleAnimation
                                            Storyboard.TargetProperty="Effect.BlurRadius"
                                            RepeatBehavior="2x"
                                            AutoReverse="True"
                                            Duration="00:00:02"
                                            From="0"
                                            To="30" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:4" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:5" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:6" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:7" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:4" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:5" Value="{StaticResource BlackSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:6" Value="{StaticResource WhiteSolidColorBrushKey}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:7" Value="{StaticResource BlackSolidColorBrushKey}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요