tags:

views:

122

answers:

1

I have the following xaml in my window:

<Border Height="100" BorderBrush="Black" BorderThickness="2" CornerRadius="10" Background="PaleVioletRed" HorizontalAlignment="Center" VerticalAlignment="Center">
   <TextBlock Margin="10"  HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="17" FontWeight="Bold">Error Message Here</TextBlock>
</Border>

Which basically displays this:
alt text

I plan to bind it's Visibility to an error state variable so it shows when an error occurs.

But I don't want to show it for a long time. I would like it to disappear/fade after 2 seconds. Is there a way to do this via XAML? Or a nice WPF way?

Something like this psudo code logic:

when (ErrorMessage.Visibility == Visible )
{
    Wait(2000); // Wait 2 seconds
    ErrorMessage.Visibility == Collapsed;
}

but preferable done with XAML.

My instincts tell me there is a way to do this with an animation, but I am not an animation expert and could use some help.

The other option is to try and setup a timer and control it with that.

+2  A: 

use something like this....

<EventTrigger RoutedEvent="Page.Loaded">

    <BeginStoryboard>
         <Storyboard BeginTime="0:0:1">
              <ObjectAnimationUsingKeyFrames Storyboard.TargetName="image1" Storyboard.TargetProperty="Visibility">
                    <DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" />
                   </ObjectAnimationUsingKeyFrames>
              </Storyboard>

    </BeginStoryboard>
    </EventTrigger>

change the routed event to match your needs, set the BeginTime on the storyboard to 2 mins ( or whatever ), set the targetname to your border element.

Muad'Dib