Storyboard to alternate Opacity between two controls
I'm trying to come up with a XAML based StoryBoard that alternates the opacity between two Label controls.
e.g.
Label1 and Label2. When the window loads, Label2 has the Opacity set to 0 by default.
I want to achieve something like:
Label1 = Opacity 1 (pause for 10 seconds) Fade Label1 Out
When Label1 is Opacity 0, fade in Label2 (pause for 10 seconds again) Fade Label2 out
Then loop this.
I've tried using Storyboard Repeats, AutoReverse and DataTriggers bound to between the two Labels but I just can'开发者_开发百科t seem to get it to function this way.
You can use a key frames animation for each label, something like that
<Label Content="LABEL1" Name="Label1">
<Label.Triggers>
<EventTrigger RoutedEvent="Label.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" RepeatBehavior="Forever">
<LinearDoubleKeyFrame Value="1" KeyTime="0:0:10"></LinearDoubleKeyFrame>
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:11"></LinearDoubleKeyFrame>
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:22"></LinearDoubleKeyFrame>
<LinearDoubleKeyFrame Value="1" KeyTime="0:0:23"></LinearDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Label.Triggers>
精彩评论