Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Window.IsVisible Property

Silverlight

Gets a value that indicates whether the window is currently visible in the user interface.

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

'Declaration
Public ReadOnly Property IsVisible As Boolean

Property Value

Type: System.Boolean
A value that indicates whether the window is currently visible.

ExceptionCondition
NotSupportedException

The application is not running outside the browser.

By default, you cannot reuse a window after it is closed. To display and hide a window multiple times, you must set its Visibility property and cancel its Closing event, as shown in the following code example. This example requires a UserControl subclass named DemoUserControl. Additionally, this example will work only in a trusted, out-of-browser application targeting Silverlight 5.


Private Sub ShowHideDemoWindowButton_Click(
    sender As System.Object, e As System.Windows.RoutedEventArgs)

    If (Not Application.Current.IsRunningOutOfBrowser OrElse _ 
        Not Application.Current.HasElevatedPermissions) Then Return

    DemoWindow.Visibility = If(DemoWindow.IsVisible,
        Visibility.Collapsed, Visibility.Visible)

End Sub

Private _demoWindow As Window
Private ReadOnly Property DemoWindow As Window
    Get
        If (Not Application.Current.IsRunningOutOfBrowser OrElse
            Not Application.Current.HasElevatedPermissions) Then Return Nothing

        If _demoWindow Is Nothing Then
            _demoWindow = New Window With
            {
                .Title = "Demo Window",
                .Content = New DemoUserControl(),
                .Height = 300, .Width = 300, .Top = 0, .Left = 0
            }

            AddHandler _demoWindow.Closing,
                Sub(sender As Object,
                    e As System.ComponentModel.ClosingEventArgs)
                    If (e.IsCancelable) Then
                        e.Cancel = True
                        _demoWindow.Visibility = Visibility.Collapsed
                    End If
                End Sub
        End If

        Return _demoWindow
    End Get
End Property


Silverlight

Supported in: 5

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

Community Additions

ADD
Show:
© 2015 Microsoft