Popup Window in WPF


This article shows you how to add controls, how to Open and Close the Popup Window.

Popup: Adding controls in Popup window

XAML code

    <Popup Name="Popup1" Width="240" Height="200" Placement="Center" IsEnabled="True" IsOpen="True" >
        <Border BorderBrush="DarkCyan" BorderThickness="3">
            <StackPanel Background="Aquamarine" VerticalAlignment="Center" Height="200">
                <StackPanel>
                    <Grid Margin="0,40,0,20" >
                        <Grid.RowDefinitions >
                            <RowDefinition Height=" 30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height=30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
</Grid.ColumnDefinitions>

<Label Name="lblPasswordReprint" Content="Password:" Grid.Row="1"
Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center"/>

<TextBox Name="txtPasswordReprint" Width=" 90" Height="20" Grid.Row="1"
Grid.Column="1" HorizontalAlignment="Left" IsEnabled="True"/>
<Label Name="lblUserName" Content=" UserName:" HorizontalAlignment="Right"
Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
<TextBox Name="txtUserNameReprint" Width=" 90" Height=" 20" Grid.Row="0"
Grid.Column="1" HorizontalAlignment="Left"/>
<Button Content="Login" Width="70" Height="30" Grid.Row="2"
Grid.Column="0"HorizontalAlignment="Right" />
<Button Content="Cancel" Width="70" Height="30" Grid.Row="2"
Grid.Column="1" HorizontalAlignment="Left" />
</Grid>
</StackPanel>
</StackPanel>
</Border>
</Popup>

Image of Popup Window

Popup.gif

How to Open a Popup Window?

Popup can be Opend by using Property IsOpen=true.

        private void ButtonShow_Click(object sender, RoutedEventArgs e)
        {
            Popup1.IsOpen = true;
        }

How to Close a Popup window?

Popup window can be closed by using a Property IsOpen=false

        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            Popup1.IsOpen = false;
        }


 

Up Next
    Ebook Download
    View all
    Learn
    View all