EventTrigger가 아닌 리소스를 사용
.NET프로그래밍/Silverlight 3.0 2009. 12. 3. 14:59 |[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(); // 스토리보드(애니메이션) 실행
}
}
}
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
ColorAnimation (0) | 2009.12.03 |
---|---|
PointAnimation (0) | 2009.12.03 |
<DoubleAnimation /> - 이미지에 Animation 효과 주기(FadeIn) (0) | 2009.12.03 |
애니메이션 (Animation) (0) | 2009.12.03 |
템플릿(Template) : 컨트롤 모양 미리 정의 (0) | 2009.12.03 |