2

I have a StatusBar TextBlock item. This show the process being under taken and status/information messages. If the message is not 'Ready' I want the text to fade away over time, leaving 'Ready' when it has gone.

I currently am testing this, and have the following XAML for the TextBlock.

<StatusBarItem DockPanel.Dock="Left" Margin="0,2,0,0">
    <TextBlock Text="{Binding StatusMessage}" 
               Margin="5,0,0,0" 
               Foreground="White">
        <TextBlock.Style>
            <Style TargetType="TextBlock">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SystemIsReady, 
                                           NotifyOnSourceUpdated=True, 
                                           Mode=TwoWay}" 
                                 Value="False">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                          From="1.0" 
                                                          To="0.5" 
                                                          Duration="0:0:1.5"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding SystemIsReady, 
                                           NotifyOnSourceUpdated=True, 
                                           Mode=TwoWay}" 
                                 Value="True">
                        <Setter Property="Opacity" Value="1.0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
</StatusBarItem>

The test method changes the text and updates the IsSytemReady if the status is equal to 'Ready'. The binding are working but the animation to fade to 0.5 opacity seems to have fired before the application is shown and the trigger to set this Opacity back to one is also not working.

Why is the animation/trigger not re-firing?

Thanks for your time.

4

1 回答 1

2

The Animation is not re-firing because the Timeline is still running, you will have to stop the Storyboard to allow the value to be reset.

You can use StopStoryboard for this, simply name the Storyboard then call StopStoryboard in the EnterActions of the true DataTrigger

Example:

<TextBlock.Style>
    <Style TargetType="{x:Type TextBlock}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding SystemIsReady, Mode=TwoWay, NotifyOnSourceUpdated=True}"  Value="False">
                <DataTrigger.EnterActions>
                    <BeginStoryboard Name="FadeOut">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1.0"  To="0.5"  Duration="0:0:1.5"/>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding SystemIsReady, Mode=TwoWay, NotifyOnSourceUpdated=True}" Value="True">
                <Setter Property="Opacity" Value="1.0"/>
                <DataTrigger.EnterActions>
                    <StopStoryboard BeginStoryboardName="FadeOut" />
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</TextBlock.Style>
于 2013-08-18T21:23:54.277 回答