IsOpen Property
Collapse the table of content
Expand the table of content

Popup.IsOpen Property

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

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

'Declaration
Public Property IsOpen As Boolean

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. 
Private p As New Popup()
Private Sub showPopup_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Create some content to show in the popup. Typically you would 
    ' create a user control. 
    Dim border As New Border()
    border.BorderBrush = New SolidColorBrush(Colors.Black)
    border.BorderThickness = New Thickness(5)

    Dim panel1 As New StackPanel()
    panel1.Background = New SolidColorBrush(Colors.LightGray)

    Dim button1 As New Button()
    button1.Content = "Close"
    button1.Margin = New Thickness(5)
    AddHandler button1.Click, AddressOf button1_Click
    Dim textblock1 As New TextBlock()
    textblock1.Text = "The popup control"
    textblock1.Margin = New Thickness(5)
    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 = 25
    p.HorizontalOffset = 25

    ' Open the popup. 
    p.IsOpen = True

End Sub

Private Sub button1_Click(ByVal sender As Object, _
    ByVal e As RoutedEventArgs)
    ' Close the popup. 
    p.IsOpen = False

End Sub



<UserControl x:Class="Popup2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    FontFamily="Trebuchet MS" FontSize="11"
    Width="200" Height="200">

        <StackPanel x:Name="LayoutRoot" Background="White">
            <Button Width="100" Height="50" x:Name="showPopup" 
            Click="showPopup_Click" Content="Show Popup" />
        </StackPanel>
</UserControl>


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2016 Microsoft