Popup.IsOpen Property

July 28, 2014

Gets or sets whether the popup is currently displaying on the screen.

Namespace:  System.Windows.Controls.Primitives
Assembly:  System.Windows (in System.Windows.dll)

public bool IsOpen { get; set; }

Property Value

Type: System.Boolean
true if the popup is currently displaying; otherwise, false. The default is false.

Dependency property identifier field: IsOpenProperty

In some cases, the IsOpen property will return true, even though the popup is not visible. For example, if the Visibility property of the popup is Collapsed, and the IsOpen property has not been explicitly set to false, the IsOpen property will return true.

Although it is read-write and technically is settable in XAML, setting a value for IsOpen in XAML is not typical. In addition, you should not template-bind to the IsOpen property. Instead, you should set a name for the popup by using the x:Name attribute and set IsOpen in code.

The following example shows how to use the IsOpen property to remove a popup from the screen. The popup content is created inline for conciseness, but you would typically create this content in a separate user control and use an instance of that control as the child of the popup.


// Create the popup object.
Popup p = new Popup();
private void showPopup_Click(object sender, RoutedEventArgs e)
{
    // Create some content to show in the popup. Typically you would 
    // create a user control.
    Border border = new Border();
    border.BorderBrush = new SolidColorBrush(Colors.Black);
    border.BorderThickness = new Thickness(5.0);

    StackPanel panel1 = new StackPanel();
    panel1.Background = new SolidColorBrush(Colors.LightGray);

    Button button1 = new Button();
    button1.Content = "Close";
    button1.Margin = new Thickness(5.0);
    button1.Click += new RoutedEventHandler(button1_Click);
    TextBlock textblock1 = new TextBlock();
    textblock1.Text = "The popup control";
    textblock1.Margin = new Thickness(5.0);
    panel1.Children.Add(textblock1);
    panel1.Children.Add(button1);
    border.Child = panel1;

    // Set the Child property of Popup to the border 
    // which contains a stackpanel, textblock and button.
    p.Child = border;

    // Set where the popup will show up on the screen.
    p.VerticalOffset = 150;
    p.HorizontalOffset = 150;

    // Open the popup.
    p.IsOpen = true;

}

void button1_Click(object sender, RoutedEventArgs e)
{
    // Close the popup.
    p.IsOpen = false;

}



<phone:PhoneApplicationPage x:Class="Popup2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    FontFamily="Trebuchet MS" FontSize="11" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="800" d:DesignWidth="480">

        <StackPanel x:Name="LayoutRoot" Background="Transparent">
            <Button x:Name="showPopup" 
            Click="showPopup_Click" Content="Show Popup" />
        </StackPanel>
</phone:PhoneApplicationPage>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft