Home > DeveloperSection > Forums > How can use popup and how can I show and hide it in wpf?
Madam Walker
Madam Walker

Total Post:22

Posted on    August-09-2013 7:17 AM


 1 Reply(s)
 1515  View(s)
Rate this:
Hi Mindstick!

How can use popup and how can I show and hide it in wpf?

thanks in Advance

Pravesh Singh

Total Post:412

Posted on    August-10-2013 5:34 AM

Xaml Code:-

Below I write the code which is show a popup and automatic hide after one second in wpf :-

<Window x:Class="WpfApplication1.MainWindow"



        Title="MainWindow" Height="350" Width="525">



        <Popup Name="popup1" PopupAnimation="Slide"  HorizontalOffset="200" VerticalOffset="-20" Height="60" VerticalAlignment="Bottom" Margin="0,0,277,128" HorizontalAlignment="Right" Width="162" Opacity="70" OpacityMask="#FF0A0808" OverridesDefaultStyle="True" StaysOpen="False" AllowsTransparency="True">



                    <ImageBrush ImageSource="/WpfApplication1;component/Images/Picture2.png" />


                <StackPanel Height="30" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="70" OpacityMask="#FFE8D3D3">

                        <Label Name="lblClose" Content="X" HorizontalAlignment="Right" Foreground="White" FontWeight="SemiBold" FontSize="15" MouseRightButtonUp="lblClose_MouseRightButtonUp" ></Label>


                    <StackPanel Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="70" OpacityMask="#FFE8D3D3">

                        <Label Content="Follwoing" Margin="45,-20,20,20"  Foreground="White" FontWeight="SemiBold" FontSize="15"></Label>






        <Button Content="Button" Height="23" HorizontalAlignment="Left"  Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Margin="75,33,0,0" BorderBrush="{x:Null}">


                <ImageBrush ImageSource="/WpfApplication1;component/Images/Picture2.png" />



        <Label Content="Label" Height="31" HorizontalAlignment="Right"  Name="label1" VerticalAlignment="Bottom" HorizontalContentAlignment="Right" Margin="0,0,129,59"/>




Cs file

namespace WpfApplication1


    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    public partial class MainWindow : Window


        public MainWindow()





        System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();

        private void button1_Click(object sender, RoutedEventArgs e)



            timer.Interval = new TimeSpan(0, 0, 1);

            timer.Tick += new EventHandler(tickTime);


            popup1.Margin = new Thickness(-50, -100, 0, 0);

            popup1.PlacementTarget = label1;


            popup1.IsOpen = true;


        private void tickTime(object sender, EventArgs e)


            if (timer.Interval.Seconds == 1)


                popup1.IsOpen = false;




        private void lblClose_MouseRightButtonUp(object sender, MouseButtonEventArgs e)


            popup1.IsOpen = false;




Don't want to miss updates? Please click the below button!

Follow MindStick