In UWP we have this great control called Popup this control can allow you to quickly and cleanly have element pop in and pop out of your view. Also we will look at how to do more of less the same thing with only a Grid.
In this post I wont go into details about the popup control itselft however if you are interested in getting more information msdn is the best place to look.
First we are going to create our simple popup element, make sure that you set the IsOpen property to false (this will hide your popup), IsLightDismissEnabled to true will mean that if the user clicks outside of the popup it will disappear.
Here is what the XAML can look like:
To add transition to when the popup will be shown we will add ChildTransitions:
This will add an animation, the popup will come from the bottom with a translation of 100px. If you have wanted a Horizontal translation then you could have used FromHorizontalOffset.
For this popup to be displayed all you need is to set the IsOpen to true :
Now if we wanted the popup to hide it self after 3 seconds all we would need to add is a wait of 3 seconds and again change the IsOpen to false as follows:
In the previous example we used the default popup control which allowed us to use the lightdismiss and directly attach the PopupThemeTransition animations to the popup. However we always have custome cases where we need custome code and sometimes the default controls just wont cut it. NOw we are going to see how to use a Grid as a popup.
first we are going to create our Grid as follows:
Next we are going to add storyboards and use PopInThemeAnimation and PopOutThemeAnimation
to pop in and pop out our grid. Here is the Storyboard XAML code:
and now to easily call this code all we need to do:
And there you are! You can find the full code here.