WPF Trigger animation when Visibility is changed?

Peter picture Peter · Feb 18, 2010 · Viewed 9.9k times · Source

Well i have a custom control and when Visibility is changed to Visible I have a Trigger with a enter/exit action but the problem is that when the exit action fires the Visibility is no longer Visible so the animation can't be seen how would I fix this?

here is my Trigger:

<ControlTemplate.Triggers>
    <Trigger Property="Visibility" Value="Visible">
        <Trigger.ExitActions>
            <BeginStoryboard Storyboard="{StaticResource Hide}"/>
        </Trigger.ExitActions>
        <Trigger.EnterActions>
            <BeginStoryboard Storyboard="{StaticResource Show}"/>
        </Trigger.EnterActions>
    </Trigger>
</ControlTemplate.Triggers>

Answer

Dabblernl picture Dabblernl · Feb 18, 2010

I tried this too and failed. I think it is not possible to accomplish this in a simple ControlTemplate with a Trigger on the Visibility property. What you can do is add an Opacity animation From 1 To 0 to a Trigger for a different property, for instance a DependencyProperty that you add in the code behind yourself.