[MainPage.xaml]


<UserControl x:Class="RiaStoryBoard.MainPage"

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

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

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

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

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <!--[1] 스토리보드 정의-->

        <Grid.Resources>

            <Storyboard x:Name="myStory">

                <DoubleAnimation

                    Storyboard.TargetName="rect"

                    Storyboard.TargetProperty="Opacity"

 

                    Duration="0.0:0:5.0"

                    From="0.0"

                    To="1.0"

                    AutoReverse="True"

                    RepeatBehavior="Forever"

                />

            </Storyboard>

        </Grid.Resources>

 

        <!--[2] 애니메이션 사용-->

        <Rectangle x:Name="rect" Fill="Yellow" Stroke="Red" StrokeThickness="1"

            RadiusX="10" RadiusY="10" Width="100" Height="100"

        >

        </Rectangle>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaStoryBoard

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.rect.MouseEnter += new MouseEventHandler(rect_MouseEnter);

            this.rect.MouseLeave += new MouseEventHandler(rect_MouseLeave);

        }

 

        void rect_MouseLeave(object sender, MouseEventArgs e)

        {

            this.myStory.Stop(); // 멈춤

        }

 

        void rect_MouseEnter(object sender, MouseEventArgs e)

        {

            this.myStory.Begin(); // 스토리보드(애니메이션) 실행

        }

    }

}

 

 
































Posted by holland14
: