方法: イベント トリガーを使用して、開始後にストーリーボードを制御する
この例では、開始後に Storyboard を制御する方法を示します。 XAML を使用して Storyboard を開始するには BeginStoryboard を使用します。これは、アニメーション化するオブジェクトとプロパティにアニメーションを配布し、ストーリーボードを開始します。 Name プロパティを指定して BeginStoryboard 名前を付ける場合は、それを制御可能なストーリーボードにします。 その後、ストーリーボードの開始後に対話形式でストーリーボードを制御できます。
ストーリーボードを制御するには、次のストーリーボード アクション EventTrigger オブジェクトと共に使用します。
PauseStoryboard: ストーリーボードを一時停止します。
ResumeStoryboard: 一時停止したストーリーボードを再開します。
SetStoryboardSpeedRatio: ストーリーボードの速度を変更します。
SkipStoryboardToFill: ストーリーボードを、それがある場合に限り、その填充期間の終わりまで進めます。
StopStoryboard: ストーリーボードを停止します。
RemoveStoryboard: ストーリーボードを削除し、リソースを解放します。
例
次の例では、制御可能なストーリーボード アクションを使用してストーリーボードを対話形式で制御します。
手記
コードを使用してストーリーボードを制御する例については、「対話型メソッドの使用を開始した後にストーリーボードを制御する」を参照してください。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Controlling a Storyboard" >
<StackPanel Margin="20" >
<!-- This rectangle is animated. -->
<Rectangle Name="myRectangle"
Width="100" Height="20" Margin="12,0,0,5" Fill="#AA3333FF" HorizontalAlignment="Left" />
<!-- This StackPanel contains all the Buttons. -->
<StackPanel Orientation="Horizontal" Margin="0,30,0,0">
<Button Name="BeginButton">Begin</Button>
<Button Name="PauseButton">Pause</Button>
<Button Name="ResumeButton">Resume</Button>
<Button Name="SeekButton">Seek</Button>
<Button Name="SkipToFillButton">Skip To Fill</Button>
<Button Name="SetSpeedRatioButton">Triple Speed</Button>
<Button Name="StopButton">Stop</Button>
<StackPanel.Triggers>
<!-- Begin the Storyboard -->
<EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton">
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard >
<DoubleAnimation
Storyboard.TargetName="myRectangle"
Storyboard.TargetProperty="Width"
Duration="0:0:5" From="100" To="500" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<!-- Pause the Storyboard -->
<EventTrigger RoutedEvent="Button.Click" SourceName="PauseButton">
<PauseStoryboard BeginStoryboardName="MyBeginStoryboard" />
</EventTrigger>
<!-- Resume the Storyboard -->
<EventTrigger RoutedEvent="Button.Click" SourceName="ResumeButton">
<ResumeStoryboard BeginStoryboardName="MyBeginStoryboard" />
</EventTrigger>
<!-- Seek one second into the storyboard's active period. -->
<EventTrigger RoutedEvent="Button.Click" SourceName="SeekButton">
<SeekStoryboard
BeginStoryboardName="MyBeginStoryboard"
Offset="0:0:1" Origin="BeginTime" />
</EventTrigger>
<!-- Skip to Fill -->
<EventTrigger RoutedEvent="Button.Click" SourceName="SkipToFillButton">
<SkipStoryboardToFill BeginStoryboardName="MyBeginStoryboard" />
</EventTrigger>
<!-- Stop the Storyboard -->
<EventTrigger RoutedEvent="Button.Click" SourceName="StopButton">
<StopStoryboard BeginStoryboardName="MyBeginStoryboard" />
</EventTrigger>
<!-- Triple the speed of the Storyboard -->
<EventTrigger RoutedEvent="Button.Click" SourceName="SetSpeedRatioButton">
<SetStoryboardSpeedRatio SpeedRatio="3" BeginStoryboardName="MyBeginStoryboard" />
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</StackPanel>
</Page>
その他の例については、アニメーションサンプル ギャラリーのを参照してください。
関連項目
.NET Desktop feedback