負荷のストーリーボードのアニメーションを開始するためのXAMLプロパティ
-
21-09-2019 - |
質問
さて、タイトルが示すとおります:
私は、ストーリーボードを持っていると私はそれのアニメーションは、コードの介入なしに開始します。 この要件の理由は、私が埋め込まれたSilverlightをターゲットにしていると私は同様に自分のアプリケーションを再コンパイルするために、今が面倒だということです。そして、それを考えるために来て、それだけで将来的にアニメーションを変更することが容易になります。
んXAML?すぐにXAMLの負荷などとして、ストーリーボードの実行をする性質を持っている。
解決
あなたのストーリーボード
を開始するLoadedイベントを使用することができますたとえば、参照してくださいMSDN: ストーリーボード(シルバー)の
MSDNからの例を選んだ:
<Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Rectangle
x:Name="MyAnimatedRectangle"
Width="100"
Height="100"
Fill="Blue">
<Rectangle.Triggers>
<!-- Animates the rectangle's opacity.
This is the important part, the EventTrigger which will start our animation -->
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyAnimatedRectangle"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</Canvas>
オブジェクト矩形が特性を有します。トリガーのプロパティでは、このイベントが発生しますとき発生しますEventTriggerを定義しました。私たちは、ロードされたときに、それが発火する手段Rectangle.Loadedイベントを、選択し;。)
私たちは、ストーリーボードを開始するBeginStoryboardプロパティを追加し、ストーリーボードを追加します。このアニメーションは、どの手段5秒の期間では、不透明度が徐々にフェードゼロになり、バック(オートリバースプロパティ)と、それは永遠(RepeatBehaviourプロパティ)これを実行することを、OpacityプロパティにDoubleAnimationを使用します。
他のヒント
<UserControl x:Class="SOSMVVM.AniM11"
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'
mc:Ignorable='d'
d:DesignWidth='640'
d:DesignHeight='480'>
<StackPanel Margin="5">
<Rectangle Name="rect3" Fill="Blue" Margin="2" Width="20"
Height="20" HorizontalAlignment="Left" />
<Button Margin="2,20,0,0" HorizontalAlignment="Left"
Content="Start Animations" Width="100">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="rect3" Storyboard.TargetProperty="Width"
From="20" To="400" Duration="0:0:10" SpeedRatio="0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
</UserControl>
所属していません StackOverflow