共用方式為


HOW TO:使用主要畫面格建立大小變更的動畫

本範例說明如何使用主要畫面格建立大小變更的動畫。

範例

下列範例會使用 SizeAnimationUsingKeyFrames 類別將 ArcSegmentSize 屬性顯示為動畫。 這個動畫以下列方式使用三個主要畫面格。

  1. 在動畫的前半秒,使用 LinearSizeKeyFrame 類別的執行個體,逐漸增加弧形的大小。 線性的主要畫面格 (例如 LinearSizeKeyFrame) 會在兩個值之間建立平滑的線性轉換。

  2. 在後半秒結尾,使用 DiscreteSizeKeyFrame 類別的執行個體,突然增加弧形的大小。 不連續的主要畫面格 (例如 DiscreteSizeKeyFrame) 會在值之間建立突然的跳躍點,也就是說,大小會突然變更而且很明顯。

  3. 在最後兩秒,使用 SplineSizeKeyFrame 類別的執行個體,增加弧形的大小。 曲線主要畫面格 (例如 SplineSizeKeyFrame) 會根據 KeySpline 屬性的值建立值之間的可變轉換。 在這個範例中,弧形一開始會緩慢增加大小,接著當接近時間區段結尾時會呈指數增加。

<!-- This example shows how to use the SizeAnimationUsingKeyFrames to animate the
size of an ArcSegment. -->
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://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>

如需完整範例,請參閱 KeyFrame 動畫範例 (英文)。

請參閱

參考

SizeAnimationUsingKeyFrames

Size

ArcSegment

LinearSizeKeyFrame

DiscreteSizeKeyFrame

SplineSizeKeyFrame

概念

主要畫面格動畫概觀

其他資源

主要畫面格動畫 HOW TO 主題