Udostępnij za pośrednictwem


Window.WindowState Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether the window is maximized, minimized, or in the normal state.

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

Syntax

'Declaration
Public Property WindowState As WindowState
public WindowState WindowState { get; set; }

Property Value

Type: System.Windows.WindowState
A value that indicates the current state of the window. The default is Normal.

Exceptions

Exception Condition
NotSupportedException

The application is not running outside the browser.

UnauthorizedAccessException

The current thread is not the user interface (UI) thread.

SecurityException

When setting this property, except in response to a user-initiated action, the Application.Startup event has already occurred and Application.HasElevatedPermissions is false.

Remarks

You use this property to provide an alternative to the window Minimize and Maximize buttons. This is particularly useful in trusted applications when you hide the window title bar and border. For information, see How to: Configure an Application for Out-of-Browser Support.

You can set this property only in the following cases:

Examples

The following code example demonstrates the use of this property.

' Maximize the main window.
Private Sub MaxButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    If Application.Current.IsRunningOutOfBrowser Then
        Application.Current.MainWindow.WindowState = WindowState.Maximized
    End If
End Sub
// Maximize the main window.
private void MaxButton_Click(object sender, RoutedEventArgs e)
{
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.MainWindow.WindowState = WindowState.Maximized;
    }
}

Version Information

Silverlight

Supported in: 5, 4

Platforms

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