views:

640

answers:

2

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>
+2  A: 

Hi Petoj :)

That's right. Tricky stuff. I'd solve this problem with attached properties + value coercion. Take a look here: WPF Fade Animation.

Hope this helps.

Cheers, Anvaka.

Anvaka
Does this have a fade animation in it? can i edit this so it only delays the hide/collapse until my animation is done?
Petoj
I'm wondering the same thing as Petoj.
jpierson
@Petoj, @jpierson: Of course you can do whatever you want with the code. It has build-in animation, and I would go with suggested approach in my sample. Because waiting for external animation to complete sounds like unnecessary complexity. Though if you really want to have it, you can make attached property value more sophisticated, and pass animation as one of its values... I feel like it's hard to give complete solution in this comment. If you need more, please post a question, and I'll give more elaborate answer :).
Anvaka
+1  A: 

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 Dependency property that you add in the code behind yourself.

Dabblernl