次の方法で共有


方法 : キー フレームを使用して境界線の太さをアニメーション化する

更新 : 2007 年 11 月

この例では、BorderBorderThickness プロパティをアニメーション化する方法を説明します。

使用例

次のコード例では、ThicknessAnimationUsingKeyFrames クラスを使用して BorderBorderThickness プロパティにアニメーションを適用しています。このアニメーションは、次の方法で 3 つのキー フレームを使用します。

  1. 最初の 0.5 秒間は、LinearThicknessKeyFrame クラスのインスタンスを使用して、境界線の太さを徐々に太くします。この例では、LinearThicknessKeyFrame を使用して、値から値への滑らかで直線的な増加を作成します。

  2. 次の 0.5 秒間の終わりには、DiscreteThicknessKeyFrame クラスのインスタンスを使用して、境界線の太さを突然太くします。DiscreteThicknessKeyFrame からこのような不連続のキー フレームを派生すると、値の間に急なジャンプを作成します。つまり、アニメーションの動きはぎくしゃくします。

  3. 最後の 2 秒間は、SplineThicknessKeyFrame クラスのインスタンスを使用して、境界線の太さを細くします。SplineThicknessKeyFrame からこのようなスプライン キー フレームを派生すると、KeySpline プロパティの値に従って、値の間に可変遷移が作成されます。このキー フレームでは、アニメーションはゆっくりと始まりますが、時間セグメントの終点に向かって急激に速くなります。

<!-- This example shows how to use the ThicknessAnimationUsingKeyFrames to create
an animation on the BorderThickness property of a Border. -->
<Page  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="Microsoft.Samples.KeyFrameExamples.ThicknessAnimationUsingKeyFramesExample"
  Name="myRootElement"
  WindowTitle="ThicknessAnimationUsingKeyFrames Example">

  <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
    <Border Background="#99FFFFFF" BorderBrush="#CCCCFF" BorderThickness="1"
    Margin="0,60,0,20" Padding="20"  >
      <Border.Triggers>
        <EventTrigger RoutedEvent="Border.Loaded">
          <BeginStoryboard>
            <Storyboard>

              <!-- Animating the BorderThickness property uses 3 KeyFrames. -->
              <ThicknessAnimationUsingKeyFrames
                Storyboard.TargetProperty="BorderThickness"
                Duration="0:0:5" FillBehavior="HoldEnd" RepeatBehavior="Forever">
                <ThicknessAnimationUsingKeyFrames.KeyFrames>

                  <!-- Using a LinearThicknessKeyFrame, thickness increases gradually
                  over the first half second of the animation. -->
                  <LinearThicknessKeyFrame KeyTime="0:0:0.5">
                    <LinearThicknessKeyFrame.Value>
                      <Thickness Left="8" Right="8" Top="6" Bottom="6" />
                    </LinearThicknessKeyFrame.Value>
                  </LinearThicknessKeyFrame>

                  <!-- Using a DiscreteThicknessKeyFrame, thickness increases suddenly
                  after the first second of the animation. -->
                  <DiscreteThicknessKeyFrame KeyTime="0:0:1">
                    <DiscreteThicknessKeyFrame.Value>
                      <Thickness Left="28" Right="28" Top="24" Bottom="24" />
                    </DiscreteThicknessKeyFrame.Value>
                  </DiscreteThicknessKeyFrame>

                  <!-- Using a SplineThicknessKeyFrame, thickness decreases slowly at first
                  and then suddenly contracts. This KeyFrame takes 2 seconds. -->
                  <SplineThicknessKeyFrame KeySpline="0.6,0.0 0.9,0.00" KeyTime="0:0:3">
                    <SplineThicknessKeyFrame.Value>
                      <Thickness Left="1" Right="1" Top="1" Bottom="8" />
                    </SplineThicknessKeyFrame.Value>
                  </SplineThicknessKeyFrame>

                </ThicknessAnimationUsingKeyFrames.KeyFrames>
              </ThicknessAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Border.Triggers>

      <TextBlock>
        This example shows how to use the ThicknessAnimationUsingKeyFrames to create
        an animation on the BorderThickness property of a Border. 
      </TextBlock>
    </Border>

  </StackPanel>
</Page>

サンプル全体については、「KeyFrame アニメーションのサンプル」を参照してください。

参照

処理手順

KeyFrame アニメーションのサンプル

方法 : BorderThickness 値をアニメーション化する

概念

キー フレーム アニメーションの概要

参照

LinearThicknessKeyFrame

DiscreteThicknessKeyFrame

SplineThicknessKeyFrame

その他の技術情報

キー フレーム アニメーションに関する「方法」トピック