■ 움직이는 사각형 애니메이션 만들기

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

<Canvas

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

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

    <Rectangle

        Name="rectangle"

        Canvas.Left="96"

        Canvas.Top="96"

        Width="192"

        Height="192"

        Stroke="Black">

        <Rectangle.Fill>

            <LinearGradientBrush x:Name="brush">

                <LinearGradientBrush.GradientStops>

                    <GradientStop Offset="0" Color="Red" />

                    <GradientStop Offset="1" Color="Blue" />

                </LinearGradientBrush.GradientStops>

            </LinearGradientBrush>

        </Rectangle.Fill>

    </Rectangle>

    <Canvas.Triggers>

        <EventTrigger RoutedEvent="Canvas.Loaded">

            <BeginStoryboard>

                <Storyboard>

                    <DoubleAnimation

                        Storyboard.TargetName="rectangle"

                        Storyboard.TargetProperty="Width"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:0.1"

                        From="192"

                        To="204" />

                    <DoubleAnimation

                        Storyboard.TargetName="rectangle"

                        Storyboard.TargetProperty="Height"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:0.1"

                        From="192"

                        To="204" />

                    <DoubleAnimation

                        Storyboard.TargetName="rectangle"

                        Storyboard.TargetProperty="(Canvas.Left)"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:0.1"

                        From="96"

                        To="90" />

                    <DoubleAnimation

                        Storyboard.TargetName="rectangle"

                        Storyboard.TargetProperty="(Canvas.Top)"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:0.1"

                        From="96"

                        To="90" />

                    <PointAnimation

                        Storyboard.TargetName="brush"

                        Storyboard.TargetProperty="StartPoint"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:5"

                        From="0 0"

                        To="1 0" />

                    <PointAnimation

                        Storyboard.TargetName="brush"

                        Storyboard.TargetProperty="EndPoint"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:5"

                        From="1 1"

                        To="0 1" />

                    <ColorAnimation

                        Storyboard.TargetName="brush"

                        Storyboard.TargetProperty="GradientStops[0].Color"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:1"

                        From="Red"

                        To="Blue" />

                    <ColorAnimation

                        Storyboard.TargetName="brush"

                        Storyboard.TargetProperty="GradientStops[1].Color"

                        RepeatBehavior="Forever"

                        AutoReverse="True"

                        Duration="0:0:1"

                        From="Blue"

                        To="Red" />

                </Storyboard>

            </BeginStoryboard>

        </EventTrigger>

    </Canvas.Triggers>

</Canvas>

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

Posted by 사용자 icodebroker

댓글을 달아 주세요