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

728x90
반응형
728x170

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"
    xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
    Width="800"
    Height="600"
    Title="LinearGradientBrush 클래스 : 애니메이션 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Padding"    Value="10"    />
            <Setter Property="Background" Value="White" />
            <Setter Property="BitmapEffect">
                <Setter.Value>
                    <OuterGlowBitmapEffect GlowColor="White" />
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type Rectangle}">
            <Setter Property="BitmapEffect">
                <Setter.Value>
                    <DropShadowBitmapEffect />
                </Setter.Value>
            </Setter>
        </Style>
        <DrawingBrush x:Key="CheckDrawingBrushKey" 
            ViewportUnits="Absolute"
            Viewport="0 0 10 10"
            TileMode="Tile"
            o:Freeze="True">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="White">
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0 0 1 1" />
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                    <GeometryDrawing Brush="#e2e2e2"
                        Geometry="M 0 0 L 0 0.5 0.5 0.5 0.5 1 1 1 1 0.5 0.5 0.5 0.5 0" />
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Window.Resources>
    <StackPanel
        HorizontalAlignment="Center"
        Orientation="Horizontal">
        <StackPanel
            VerticalAlignment="Center"
            Margin="10"
            Background="{StaticResource CheckDrawingBrushKey}">
            <TextBlock>GradientStop.Offset 속성 애니메이션</TextBlock>
            <Rectangle
                Margin="10"
                Width="200"
                Height="100"
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush>
                        <GradientStop                        Color="MediumBlue" Offset="0.0" />
                        <GradientStop x:Name="gradientStop1" Color="Purple"     Offset="0.5" />
                        <GradientStop                        Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation 
                                    Storyboard.TargetName="gradientStop1"
                                    Storyboard.TargetProperty="Offset"
                                    FillBehavior="Stop"
                                    From="0.0"
                                    To="1.0"
                                    Duration="0:0:3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
            <TextBlock>GradientStop.Color 속성 애니메이션</TextBlock>
            <Rectangle
                Margin="10"
                Width="200"
                Height="100" 
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush>
                        <GradientStop                        Color="MediumBlue" Offset="0.0" />
                        <GradientStop x:Name="gradientStop2" Color="Purple"     Offset="0.5" />
                        <GradientStop                        Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation 
                                    Storyboard.TargetName="gradientStop2"
                                    Storyboard.TargetProperty="Color"
                                    FillBehavior="Stop"
                                    From="Purple"
                                    To="Yellow"
                                    Duration="0:0:3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
            <TextBlock>GradientStop.Opacity 속성 애니메이션</TextBlock>
            <Rectangle
                Margin="10"
                Width="200"
                Height="100"
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush>
                        <GradientStop                        Color="MediumBlue" Offset="0.0" />
                        <GradientStop x:Name="gradientStop3" Color="Purple"     Offset="0.5" />
                        <GradientStop                        Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation 
                                    Storyboard.TargetName="gradientStop3"
                                    Storyboard.TargetProperty="Color" 
                                    FillBehavior="Stop"
                                    Duration="0:0:3">
                                        <ColorAnimation.By>
                                            <Color ScA="-1" ScR="0" ScB="0" ScG="0" />
                                        </ColorAnimation.By>
                                </ColorAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
        </StackPanel>
        <StackPanel
            VerticalAlignment="Center"
            Margin="10"
            Background="{StaticResource CheckDrawingBrushKey}">
            <TextBlock>StartPoint 속성 애니메이션</TextBlock>
            <Rectangle 
                Margin="10"
                Width="200" 
                Height="100"
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush x:Name="linearGradientBrush1">
                        <GradientStop Color="MediumBlue" Offset="0.0" />
                        <GradientStop Color="Purple"     Offset="0.5" />
                        <GradientStop Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <PointAnimation 
                                    Storyboard.TargetName="linearGradientBrush1"
                                    Storyboard.TargetProperty="StartPoint"
                                    FillBehavior="Stop"
                                    From="0 0"
                                    To="0.5 1"
                                    Duration="0:0:3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
            <TextBlock>EndPoint 속성 애니메이션</TextBlock>
            <Rectangle
                Margin="10"
                Width="200"
                Height="100"
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush x:Name="linearGradientBrush2"
                        StartPoint="0 0"
                        EndPoint="1 1">
                        <GradientStop Color="MediumBlue" Offset="0.0" />
                        <GradientStop Color="Purple"     Offset="0.5" />
                        <GradientStop Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <PointAnimation 
                                    Storyboard.TargetName="linearGradientBrush2"
                                    Storyboard.TargetProperty="EndPoint"
                                    FillBehavior="Stop"
                                    From="1 1"
                                    To="0.5 0"
                                    Duration="0:0:3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
            <TextBlock>StartPoint/EndPoint 속성 애니메이션</TextBlock>
            <Rectangle 
                Margin="10"
                Width="200"
                Height="100"
                Stroke="Black"
                StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush x:Name="linearGradientBrush3">
                        <GradientStop Color="MediumBlue" Offset="0.0" />
                        <GradientStop Color="Purple"     Offset="0.5" />
                        <GradientStop Color="Red"        Offset="1.0" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <PointAnimation 
                                    Storyboard.TargetName="linearGradientBrush3"
                                    Storyboard.TargetProperty="StartPoint"
                                    FillBehavior="Stop"
                                    From="0 0"
                                    To="0.5 1"
                                    Duration="0:0:3" />
                                <PointAnimation 
                                    Storyboard.TargetName="linearGradientBrush3"
                                    Storyboard.TargetProperty="EndPoint"
                                    FillBehavior="Stop"
                                    From="1 1"
                                    To="0.5 0"
                                    Duration="0:0:3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
            </Rectangle>
        </StackPanel>
    </StackPanel>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요