Gets or sets the main window of the application.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
is set from an application that's hosted in a browser, such as an XAML browser applications (XBAPs).
You can specify a different main window by setting assigning another Windows object to the property.
It is possible to set the property from XAML, if an application's main window is not the window that is produced by setting the StartupUri property in XAML. The two limitations of the XAML approach are:
You must set the Visibility property of the window you specify, otherwise it won't be shown.
The reference to the first Window object to be instantiated is also added as the first item to the Windows collection. If is subsequently set with a reference to a different Window, the position of the item with the reference to the main window will change, while the order of items in Windows remains the same. Consequently, always use to refer to the main window instead of the first item in Windows.
The following example shows how to find the main application window.
The following example shows how to set using XAML.
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="StartupWindow.xaml" > <Application.MainWindow> <NavigationWindow Source="MainPage.xaml" Visibility="Visible"></NavigationWindow> </Application.MainWindow> </Application>
The following example shows how to instantiate the in code during application startup.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.