この例では、非アクティブなアニメーション化されたプロパティ FillBehavior に対して Timeline を指定する方法を示します。
例
FillBehavior の Timeline プロパティは、アニメーション化されていない場合、つまり、Timeline が非アクティブであるが、親 Timeline がアクティブまたは保留期間内にある場合に、アニメーション化されたプロパティの値に対して何が起こるかを決定します。 たとえば、アニメーションが終了した後もアニメーション化されたプロパティは終了値のままですか、それともアニメーションが開始される前の値に戻りますか?
次の例では、DoubleAnimation を使用して、2 つの四角形の Width をアニメーション化します。 各四角形は、異なる Timeline オブジェクトを使用します。
1 つの Timeline には、FillBehaviorに設定された Stop があります。これにより、Timeline の終了時に四角形の幅がアニメーション化されていない値に戻ります。 もう 1 つの Timeline には FillBehaviorの HoldEnd があり、これにより、Timeline の終了時に幅が終了値のままになります。
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<StackPanel Margin="20">
<Border Background="#99FFFFFF">
<TextBlock Margin="20">
This example shows how the FillBehavior property determines how an animation behaves
after it reaches the end of its duration.
</TextBlock>
</Border>
<TextBlock>FillBehavior="Deactivate"</TextBlock>
<Rectangle Name="deactiveAnimationRectangle" Width="20" Height="20" Fill="#AA3333FF" HorizontalAlignment="Left" >
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<!-- The animated rectangle's width reverts back to its non-animated value
after the animation ends. -->
<DoubleAnimation
Storyboard.TargetName="deactiveAnimationRectangle"
Storyboard.TargetProperty="Width"
From="100" To="400" Duration="0:0:2" FillBehavior="Stop" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
<TextBlock Margin="0,20,0,0">FillBehavior="HoldEnd" </TextBlock>
<Rectangle Name="holdEndAnimationRectangle" Width="20" Height="20" Fill="#AA3333FF" HorizontalAlignment="Left" >
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<!-- The animated rectangle's width remains at its end value after the
animation ends. -->
<DoubleAnimation Storyboard.TargetName="holdEndAnimationRectangle"
Storyboard.TargetProperty="Width"
From="100" To="400" Duration="0:0:2" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</StackPanel>
</Page>
完全なサンプルについては、「アニメーションサンプルギャラリー
こちらも参照ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback