简体   繁体   中英

WPF Popup Closing Animatiom

 <Popup     
            AllowsTransparency="True" 
            Focusable="False"                                
            PopupAnimation="Slide"  
            Width="{Binding ElementName=grid,Path=ActualWidth}"
            Height ="{Binding ElementName=grid,Path=ActualHeight}"
            Name="popup" 
            Placement="Relative" 
            PlacementTarget="{Binding grid}" >                    
        </Popup>

This popup opens by slide animation perfectly when i set it's IsOpen Property to True. but why Popup closes immediately without any animation. Is there a way to animate Popup closing ?

The current WPF implementation only supports the PopupAnimation.Fade animation for closing the popup.

You can check this in the source code :

if (animation == PopupAnimation.Fade)
{
    _popupRoot.Value.SetupFadeAnimation(AnimationDelayTime, visible);
    return true;
}
else if (visible) // only translate when showing popup
{
    // translate the content
    _popupRoot.Value.SetupTranslateAnimations(animation, AnimationDelayTime, AnimateFromRight, AnimateFromBottom);
    return true;
}

For PopupAnimation.Fade , both the showing and the closing are animated. For other animation types, only the visible (showing) state is animated.

You cannot change this behavior. You could of course attach a custom animation to your content, but the popup will be closed immediately anyway, so you won't see it:

if (!animating)
    _secHelper.HideWindow();

If you can, use adorners instead of popups. There, you can setup your animation as you need. Alternatively, use the fade animation for popups.

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