I have a TextBlock
which will animate when a user saves his settings to the database.
But the problem is, the animation only has to run when the save to the database has been successful.
If the save was a success: Show text Saved successfully
with white text and fade out after a few second.
If the save was a failure: Show text An error has occured
with red text and do NOT fade out
Currently I have this XAML but this will always animate:
I have no idea how I can make the EventTrigger
conditionally. Any help will be appreciated!
<TextBlock Text="{Binding Message, NotifyOnTargetUpdated=True}" TextAlignment="Center" Padding="5" Grid.Row="3" Grid.Column="3" VerticalAlignment="Top">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#FFE8E8E8"/>
<Style.Triggers>
<DataTrigger Binding="{Binding HasError}" Value="True">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard x:Name="sb">
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation BeginTime="0:0:0.0" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0"/>
<DoubleAnimation BeginTime="0:0:5.0" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.5"/>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:5.5" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
If I had to do it in code:
if ("Message property has been changed" && HasError == false)
The save was a succes!
else if ("Message property has been changed" && HasError == true)
The save was a failure!