Export (0) Print
Expand All

Window.Height Property

Silverlight

Gets or sets the height of the application window in pixels.

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

public double Height { get; set; }

Property Value

Type: System.Double
The height of the application window in pixels. The default is the WindowSettings.Height setting in the application manifest.

ExceptionCondition
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.

ArgumentOutOfRangeException

The specified value when setting this property is greater than the available screen height.

You can set this property only in the following cases:

The minimum window height is dictated by the operating system. If you set this property to a value below this minimum, the value is ignored.

The following code example demonstrates the use of this property. In this example, the window position and dimensions were previously saved to the ApplicationSettings in the isolated storage as a user defined key/value pair. These key/value pairs are retrieved and used to set the current value of the window settings.


private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MainPage();

    // Set the window position and dimensions to the previoius settings.
    // The key/value pairs in the ApplicationSettings are user defined.
    if (Application.Current.IsRunningOutOfBrowser)
    {
        // Get the application settings from IsolatedStorage.
        IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;

        // Get a reference to the main window.
        Window mainWindow = Application.Current.MainWindow;

        // Set the Window.Top property.
        if (appSettings.Contains("WindowTop"))
        {
            mainWindow.Top = Convert.ToDouble(appSettings["WindowTop"]);
        }

        // Set the Window.Left property.
        if (appSettings.Contains("WindowLeft"))
        {
            mainWindow.Left = Convert.ToDouble(appSettings["WindowLeft"]);
        }

        // Set the Window.Width property.
        if (appSettings.Contains("WindowWidth"))
        {
            mainWindow.Width = Convert.ToDouble(appSettings["WindowWidth"]);
        }

        // Set the Window.Height property.
        if (appSettings.Contains("WindowHeight"))
        {
            mainWindow.Height = Convert.ToDouble(appSettings["WindowHeight"]);
        }
    }
}


Silverlight

Supported in: 5, 4

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