操作說明:使用主要畫面格建立大小變更的動畫
這個範例示範如何使用主要畫面格建立大小變更的動畫。
範例
下列範例使用 SizeAnimationUsingKeyFrames 類別,以針對 Size 的 ArcSegment 屬性建立動畫。 這個動畫會以下列方式使用三個主要畫面格:
在動畫的前半秒期間,使用 LinearSizeKeyFrame 類別的執行個體來逐漸增加弧線的大小。LinearSizeKeyFrame 這類線性主要畫面格會在值之間建立平滑的線性過渡。
在下半秒結束時,使用 DiscreteSizeKeyFrame 類別的執行個體來突然增加弧線的大小。DiscreteSizeKeyFrame 這類離散的主要畫面格會在值之間建立突然的跳躍點,即,突然變更大小,而且不是微量變更。
在最後兩秒,使用 SplineSizeKeyFrame 類別的執行個體來增加弧線的大小。SplineSizeKeyFrame 這類曲線主要畫面格會根據 KeySpline 屬性的值以在值之間建立可變的過渡。 在此範例中,弧線的大小一開始會緩慢增加,然後在接近時間區段結尾時以指數方式增加。
<!-- This example shows how to use the SizeAnimationUsingKeyFrames to animate the
size of an ArcSegment. -->
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Canvas HorizontalAlignment="Left" Margin="0" >
<!-- Create an arc on the screen that animates its size when it loads. -->
<Path Stroke="Black" StrokeThickness="2" >
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="100,200">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment x:Name="myArcSegment" Size="90,80"
SweepDirection="Clockwise" Point="500,200" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Path.Loaded">
<BeginStoryboard Name="myBeginStoryBoard">
<Storyboard>
<!-- Animating the Size property uses 3 KeyFrames. -->
<SizeAnimationUsingKeyFrames
Storyboard.TargetName="myArcSegment"
Storyboard.TargetProperty="Size" >
<SizeAnimationUsingKeyFrames.KeyFrames>
<!-- Using a LinearSizeKeyFrame, the size of the arc increases
gradually over the first half second of the animation. -->
<LinearSizeKeyFrame KeyTime="0:0:0.5" Value="120,120" />
<!-- Using a DiscreteSizeKeyFrame, the size increases suddenly
after the first second of the animation. -->
<DiscreteSizeKeyFrame KeyTime="0:0:1" Value="150,150" />
<!-- Using a SplineSizeKeyFrame, the Size increases slowly at first
and then speeds up exponentially. This KeyFrame takes 2 seconds. -->
<SplineSizeKeyFrame KeySpline="0.6,0.0 0.9,0.00" KeyTime="0:0:3" Value="300,300" />
</SizeAnimationUsingKeyFrames.KeyFrames>
</SizeAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
</Canvas>
</Page>
如需完整的範例,請參閱主要畫面格動畫範例。