简体   繁体   中英

Animate Popup before closing

I'm making a program for Windows 8 in WinRT and I'm having some trouble with the Popup-class .

The content in the popup has a fancy intro-animation when it is opened. I'd like to animate the content in the popup right before it closes, but haven't found out how.

Any ideas?

Thanks in advance

EDIT: This is an example for what I'm trying to do. The Closed-eventhandler is obviously too late for doing anything before it closes. But you get the point.

    Popup popup = new Popup();

    SolidColorBrush brush = new SolidColorBrush(Colors.Red);
    Ellipse ell = new Ellipse() { Fill = brush, Width = 300, Height = 300 };
    popup.Child = ell;

    popup.Opened += (sender, e) =>
    {
        ColorAnimation anim = new ColorAnimation() { To = Colors.Blue };
        Storyboard.SetTarget(anim, brush);
        Storyboard.SetTargetProperty(anim, "Color");

        Storyboard sb = new Storyboard();
        sb.Children.Add(anim);

        sb.Begin();
    };
    popup.Closed += (sender, e) =>
    {
        ColorAnimation anim = new ColorAnimation() { To = Colors.Green };
        Storyboard.SetTarget(anim, brush);
        Storyboard.SetTargetProperty(anim, "Color");

        Storyboard sb = new Storyboard();
        sb.Children.Add(anim);

        sb.Begin();
    };

    popup.IsOpen = true;

The problem here is that the popup has only 2 visibility states ( isopen =true/false ). when IsOpen is set to false (ie closed) the popup's visibility is set to Collapsed and the animation is not played. What I would suggest is:

The popup obviously has a close button to close it, right? So in that close button's click event, start the animation. Then listen to the completed event on the storyboard and set the popup.IsOpen=false there

sb.Completed += SomeEventHandler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM