この例では、BorderThicknessの Border プロパティをアニメーション化する方法を示します。
例
次の例では、ThicknessAnimationUsingKeyFrames クラスを使用して、BorderThicknessの Border プロパティをアニメーション化します。 このアニメーションでは、次の方法で 3 つのキー フレームを使用します。
最初の0.5秒間に、LinearThicknessKeyFrameクラスのインスタンスを使用してボーダーの太さを徐々に増やします。 この例では、LinearThicknessKeyFrame を使用して、値間の直線的な滑らかな増加を作成します。
次の後半の最後に、DiscreteThicknessKeyFrame クラスのインスタンスを使用して、境界線の太さを突然増やします。 DiscreteThicknessKeyFrame から派生したキー フレームのような個別のキー フレームは、値間の急激なジャンプを作成します。つまり、アニメーションの動きはぎくしゃくします。
最後の 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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 アニメーションのサンプル」を参照してください。
こちらも参照ください
.NET Desktop feedback