1

我有以下TextBlock动画

<TextBlock Text="{Binding StatusMessage}" 
                  Margin="5,0,0,0" 
                  Foreground="White">
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsSystemReady, 
                                               NotifyOnSourceUpdated=True, 
                                               Mode=OneWay}" 
                             Value="False">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="FadeOut">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                 From="1.0" 
                                                 To="0.0" 
                                                 Duration="0:0:3.5"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsSystemReady, 
                                               NotifyOnSourceUpdated=True, 
                                               Mode=OneWay}" 
                             Value="True">
                    <DataTrigger.EnterActions>
                        <StopStoryboard BeginStoryboardName="FadeOut" />
                    </DataTrigger.EnterActions>
                    <Setter Property="Opacity" Value="1.0"/>
                </DataTrigger>
                <Trigger Property="Opacity" Value="0.0">
                    <Setter Property="Text" Value="Ready"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

动画有效,但是当它完成时(即控件的不透明度为 0.0),我想在显示状态消息并优雅地消失后自动返回到就绪状态。我正在尝试使用标准执行此操作,Trigger但这并没有触发,为什么以及如何解决此问题?

谢谢你的时间。

4

1 回答 1

1

Trigger没有触发,因为属性Opacity仍然被动画锁定,但是Text如果你想使用ObjectAnimation.

例子:

<BeginStoryboard Name="FadeOut">
    <Storyboard >
        <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1.0"  To="0.0" Duration="0:0:3.5"/>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Text" BeginTime="0:0:3.5" >
            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Ready" />
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1.0"  To="1.0" BeginTime="0:0:3.5"/>
    </Storyboard>
</BeginStoryboard>

但是,在动画中设置TextReady不会将StatusMessage属性设置为Ready

于 2013-08-21T01:43:52.677 回答