키프레임 (KeyFrame) - DiscreteColorKeyFrame (끊어지는 움직임)
[MainPage.xaml]
<UserControl x:Class="RiaDiscreteColorKeyFrame.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">
<Canvas x:Name="LayoutRoot" Background="White">
<!-- 리소스 -->
<Canvas.Resources>
<Storyboard x:Name="sb">
<!-- 3초, 6초, 9초마다 오른쪽으로 100픽셀씩 끊어서 이동 -->
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="rect"
Storyboard.TargetProperty="(Canvas.Left)"
Duration="0:0:9">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<DiscreteDoubleKeyFrame KeyTime="00:00:03" Value="110"></DiscreteDoubleKeyFrame>
<DiscreteDoubleKeyFrame KeyTime="00:00:06" Value="210"></DiscreteDoubleKeyFrame>
<DiscreteDoubleKeyFrame KeyTime="00:00:09" Value="310"></DiscreteDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames.KeyFrames>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Canvas.Resources>
<!-- 요소 -->
<Rectangle x:Name="rect" Width="50" Height="50" Canvas.Left="10" Canvas.Top="10" Fill="Red" />
</Canvas>
</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 RiaDiscreteColorKeyFrame
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.rect.MouseLeftButtonDown += new MouseButtonEventHandler(rect_MouseLeftButtonDown);
}
void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
sb.Begin();
}
}
}