title: WPF Fade In / Out only runs once
body: <p>I have a Style with a Storyboard and Triggers. The animation work nicely, but only once.</p>
  
  <p>I have 2 Storyboards FadeIn and FadeOut. In the EnterActions I start the FadeIn animation and in the ExitActions the FadeOut animation. I start the whole animation in code with </p>
  
  <pre><code>TextBlock.StartFade = true;
  </code></pre>
  
  <p>When i debug the above code, with every hit StartFade is False (which is correct).</p>
  
  <p>So what do i do wrong?</p>
  
  <p>Here is the Style in XAML. FadingTextBlock is just a custom TextBlock with a StartFade dependency property.</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Controls:FadingTextBlock}"&gt;
      &lt;Setter Property="Visibility" Value="Collapsed" /&gt;
      &lt;Setter Property="StartFade" Value="False" /&gt;
      &lt;Setter Property="Opacity" Value="1.0" /&gt;
  
      &lt;Style.Resources&gt;
          &lt;Storyboard x:Key="FadeIn"&gt;
              &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Opacity)" Storyboard.TargetName="{x:Null}"&gt;
                  &lt;EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0.0" /&gt;
                  &lt;EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1.0" /&gt;
              &lt;/DoubleAnimationUsingKeyFrames&gt;
              &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Visibility)" Storyboard.TargetName="{x:Null}"&gt;
                  &lt;DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="{x:Static Visibility.Visible}"/&gt;
              &lt;/ObjectAnimationUsingKeyFrames&gt;
              &lt;BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.StartFade)" Storyboard.TargetName="{x:Null}"&gt;
                  &lt;DiscreteBooleanKeyFrame KeyTime="0:0:1.5" Value="False" /&gt;
              &lt;/BooleanAnimationUsingKeyFrames&gt;
          &lt;/Storyboard&gt;
          &lt;Storyboard x:Key="FadeOut"&gt;
              &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Opacity)" Storyboard.TargetName="{x:Null}"&gt;
                  &lt;EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1.0" /&gt;
                  &lt;EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.0" /&gt;
              &lt;/DoubleAnimationUsingKeyFrames&gt;
              &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Controls:FadingTextBlock.Visibility)" Storyboard.TargetName="{x:Null}"&gt;
                  &lt;DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="{x:Static Visibility.Collapsed}" /&gt;
              &lt;/ObjectAnimationUsingKeyFrames&gt;
          &lt;/Storyboard&gt;
      &lt;/Style.Resources&gt;
      &lt;Style.Triggers&gt;
          &lt;Trigger Property="StartFade" Value="True"&gt;
              &lt;Trigger.EnterActions&gt;
                  &lt;BeginStoryboard x:Name="In" Storyboard="{StaticResource FadeIn}" /&gt;                    
              &lt;/Trigger.EnterActions&gt;
              &lt;Trigger.ExitActions&gt;
                  &lt;BeginStoryboard x:Name="Out" Storyboard="{StaticResource FadeOut}" /&gt;                    
              &lt;/Trigger.ExitActions&gt;
          &lt;/Trigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>