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)

public bool IsVisible { get; }

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 void ShowHideDemoWindowButton_Click(object sender, RoutedEventArgs e)
{
    if (!Application.Current.IsRunningOutOfBrowser || 
        !Application.Current.HasElevatedPermissions) return;
    DemoWindow.Visibility = DemoWindow.IsVisible ?
        Visibility.Collapsed : Visibility.Visible;
}

private Window _demoWindow;
private Window DemoWindow
{
    get
    {
        if (!Application.Current.IsRunningOutOfBrowser || 
            !Application.Current.HasElevatedPermissions) return null;

        if (_demoWindow == null)
        {
            _demoWindow = new Window()
            {
                Title = "Demo Window",
                Content = new DemoUserControl(),
                Height = 300, Width = 300, Top = 0, Left = 0
            };

            _demoWindow.Closing += (sender, e) =>
            {
                if (e.IsCancelable)
                {
                    e.Cancel = true;
                    _demoWindow.Visibility = Visibility.Collapsed;
                }
            };
        }

        return _demoWindow;
    }
}


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:
© 2014 Microsoft