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

Total Post:22

Points:154
WPF 
WPF
 1760  View(s)
Ratings:
Rate this:
Hi Mindstick!

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

thanks in Advance

  1. Post:412

    Points:2888
    Re: How can use popup and how can I show and hide it in wpf?

    Hello!

    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"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
     
            <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">
                    <StackPanel>
                    <StackPanel.Background>
                        <ImageBrush ImageSource="/WpfApplication1;component/Images/Picture2.png" />
                    </StackPanel.Background>
                    <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>
                        <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>
     
                        </StackPanel>
                    </StackPanel>
            </Popup>
     
            <Button Content="Button" Height="23" HorizontalAlignment="Left"  Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Margin="75,33,0,0" BorderBrush="{x:Null}">
                <Button.Background>
                    <ImageBrush ImageSource="/WpfApplication1;component/Images/Picture2.png" />
                </Button.Background>
            </Button>
            <Label Content="Label" Height="31" HorizontalAlignment="Right"  Name="label1" VerticalAlignment="Bottom" HorizontalContentAlignment="Right" Margin="0,0,129,59"/>
        </Grid>
    </Window>

     

    Cs file

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
     
            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);
                timer.Start();
                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;
                    timer.Stop();
                }
            }
            private void lblClose_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
            {
                popup1.IsOpen = false;
            }
        }
    }

      Modified On Mar-30-2018 06:34:41 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!