Skip to content

Instantly share code, notes, and snippets.

@nasal
Last active October 9, 2018 22:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasal/c6585806ace571b18745 to your computer and use it in GitHub Desktop.
Save nasal/c6585806ace571b18745 to your computer and use it in GitHub Desktop.
XAML: Fade in and out animation
<!-- Invoke with ((Storyboard)FindResource("FadeInOut")).Begin(ControlName); -->
<ResourceDictionary>
<Storyboard x:Key="FadeInOut">
<!-- If the element has Visibility="Hidden". -->
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<!-- Endif. -->
<!-- If the element is hidden with Opacity="0.0". You need the following two lines in any case. -->
<DoubleAnimation BeginTime="0:0:0.0" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>
<DoubleAnimation BeginTime="0:0:2.5" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.5"/>
<!-- If you want to re-set Visibility="Hidden". -->
<ObjectAnimationUsingKeyFrames BeginTime="0:0:3.0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<!-- Endif. -->
</Storyboard>
</ResourceDictionary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment