xaml
<
UserControl
x:Class
="Silverlight.Common.Test"
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" >
< StackPanel HorizontalAlignment ="Left" >
< StackPanel Orientation ="Horizontal" >
< Button Width ="65" Height ="30" Margin ="2" Content ="begin" Click ="Button_Click" />
< Button Width ="65" Height ="30" Margin ="2" Content ="pause" Click ="Button_Click_1" />
< Button Width ="65" Height ="30" Margin ="2" Content ="resume" Click ="Button_Click_2" />
< Button Width ="65" Height ="30" Margin ="2" Content ="stop" Click ="Button_Click_3" />
</ StackPanel >
< Path Fill ="Green" >
< Path.Data >
< EllipseGeometry x:Name ="ellipse" Center ="50,50" RadiusX ="15" RadiusY ="15" />
</ Path.Data >
</ Path >
< StackPanel.Resources >
<!-- PointAnimation - 在两个 Point 值之间做线性内插动画处理 -->
<!--
Storyboard.TargetName - 要进行动画处理的对象的名称
Storyboard.TargetProperty - 要进行动画处理的对象的属性
BeginTime - 时间线在被触发 BeginTime 的时间后才能开始播放
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数](可为正;可为负;可为空;默认值为 0)
From - 动画的起始值
To - 动画的结束值
By - 动画从起始值开始计算,所需变化的总量(To 优先于 By)
Duration - 时间线的持续时间
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数]
Automatic - 自动确定
Forever - 无限长
AutoReverse - 动画完成后是否要原路返回。默认值为 false
RepeatBehavior - 动画重复播放的时间、次数或类型
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数]
nx - 播放次数。1x, 2x, 3x
Forever - 永久播放
SpeedRatio - 时间线的速率的倍数。默认值 1
FillBehavior - 动画结束后的行为 [System.Windows.Media.Animation.FillBehavior枚举]
FillBehavior.HoldEnd - 动画结束后,保留动画属性的结束值。默认值
FillBehavior.Stop - 动画结束后,恢复动画属性为其初始值
-->
< Storyboard x:Name ="storyboard" >
< PointAnimation Storyboard.TargetName ="ellipse" Storyboard.TargetProperty ="Center" BeginTime ="00:00:00" From ="50,50" To ="300,500" Duration ="0:0:3" AutoReverse ="True" RepeatBehavior ="3x" FillBehavior ="Stop" >
</ PointAnimation >
</ Storyboard >
</ StackPanel.Resources >
</ StackPanel >
</ UserControl >
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" >
< StackPanel HorizontalAlignment ="Left" >
< StackPanel Orientation ="Horizontal" >
< Button Width ="65" Height ="30" Margin ="2" Content ="begin" Click ="Button_Click" />
< Button Width ="65" Height ="30" Margin ="2" Content ="pause" Click ="Button_Click_1" />
< Button Width ="65" Height ="30" Margin ="2" Content ="resume" Click ="Button_Click_2" />
< Button Width ="65" Height ="30" Margin ="2" Content ="stop" Click ="Button_Click_3" />
</ StackPanel >
< Path Fill ="Green" >
< Path.Data >
< EllipseGeometry x:Name ="ellipse" Center ="50,50" RadiusX ="15" RadiusY ="15" />
</ Path.Data >
</ Path >
< StackPanel.Resources >
<!-- PointAnimation - 在两个 Point 值之间做线性内插动画处理 -->
<!--
Storyboard.TargetName - 要进行动画处理的对象的名称
Storyboard.TargetProperty - 要进行动画处理的对象的属性
BeginTime - 时间线在被触发 BeginTime 的时间后才能开始播放
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数](可为正;可为负;可为空;默认值为 0)
From - 动画的起始值
To - 动画的结束值
By - 动画从起始值开始计算,所需变化的总量(To 优先于 By)
Duration - 时间线的持续时间
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数]
Automatic - 自动确定
Forever - 无限长
AutoReverse - 动画完成后是否要原路返回。默认值为 false
RepeatBehavior - 动画重复播放的时间、次数或类型
TimeSpan - [-][日.]时:分:秒[.1位到7为的秒后的小数]
nx - 播放次数。1x, 2x, 3x
Forever - 永久播放
SpeedRatio - 时间线的速率的倍数。默认值 1
FillBehavior - 动画结束后的行为 [System.Windows.Media.Animation.FillBehavior枚举]
FillBehavior.HoldEnd - 动画结束后,保留动画属性的结束值。默认值
FillBehavior.Stop - 动画结束后,恢复动画属性为其初始值
-->
< Storyboard x:Name ="storyboard" >
< PointAnimation Storyboard.TargetName ="ellipse" Storyboard.TargetProperty ="Center" BeginTime ="00:00:00" From ="50,50" To ="300,500" Duration ="0:0:3" AutoReverse ="True" RepeatBehavior ="3x" FillBehavior ="Stop" >
</ PointAnimation >
</ Storyboard >
</ StackPanel.Resources >
</ StackPanel >
</ UserControl >
c#
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 Silverlight.Common
{
public partial class Test : UserControl
{
public Test()
{
InitializeComponent();
}
private void Button_Click( object sender, RoutedEventArgs e) {
storyboard.Begin();
}
private void Button_Click_1( object sender, RoutedEventArgs e) {
storyboard.Pause();
}
private void Button_Click_2( object sender, RoutedEventArgs e) {
storyboard.Resume();
}
private void Button_Click_3( object sender, RoutedEventArgs e) {
storyboard.Stop();
}
}
}
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 Silverlight.Common
{
public partial class Test : UserControl
{
public Test()
{
InitializeComponent();
}
private void Button_Click( object sender, RoutedEventArgs e) {
storyboard.Begin();
}
private void Button_Click_1( object sender, RoutedEventArgs e) {
storyboard.Pause();
}
private void Button_Click_2( object sender, RoutedEventArgs e) {
storyboard.Resume();
}
private void Button_Click_3( object sender, RoutedEventArgs e) {
storyboard.Stop();
}
}
}