我有一个带有故事板和触发器的样式。动画效果很好,但只有一次。
我有 2 个故事板 FadeIn 和 FadeOut。在 EnterActions 中我启动 FadeIn 动画,在 ExitActions 中启动 FadeOut 动画。我用代码开始整个动画
TextBlock.StartFade = true;
当我调试上面的代码时,每次点击 StartFade 都是 False(这是正确的)。
那么我做错了什么?
这是 XAML 中的样式。FadingTextBlock 只是一个具有 StartFade 依赖属性的自定义 TextBlock。
<Style TargetType="{x:Type Controls:FadingTextBlock}">
<Setter Property="Visibility" Value="Collapsed" />
<Setter Property="StartFade" Value="False" />
<Setter Property="Opacity" Value="1.0" />
<Style.Resources>
<Storyboard x:Key="FadeIn">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Opacity)" Storyboard.TargetName="{x:Null}">
<EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0.0" />
<EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1.0" />
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Visibility)" Storyboard.TargetName="{x:Null}">
<DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.StartFade)" Storyboard.TargetName="{x:Null}">
<DiscreteBooleanKeyFrame KeyTime="0:0:1.5" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="FadeOut">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Opacity)" Storyboard.TargetName="{x:Null}">
<EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1.0" />
<EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.0" />
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Visibility)" Storyboard.TargetName="{x:Null}">
<DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</Style.Resources>
<Style.Triggers>
<Trigger Property="StartFade" Value="True">
<Trigger.EnterActions>
<BeginStoryboard x:Name="In" Storyboard="{StaticResource FadeIn}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard x:Name="Out" Storyboard="{StaticResource FadeOut}" />
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>