* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
2.6 KiB
title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| How to: Get and Set the Main Application Window | Follow this example to get and set the main application window within Windows Presentation Foundation (WPF) application. | 03/30/2017 |
|
|
ec902bc4-4a59-46f5-8ec1-963b46789356 |
How to: Get and Set the Main Application Window
This example shows how to get and set the main application window.
Example
The first xref:System.Windows.Window that is instantiated within a Windows Presentation Foundation (WPF) application is automatically set by xref:System.Windows.Application as the main application window. The first xref:System.Windows.Window to be instantiated will most likely be the window that is specified as the startup uniform resource identifier (URI) (see xref:System.Windows.Application.StartupUri%2A).
The first xref:System.Windows.Window could also be instantiated using code. One example is opening a window during application startup, like the following:
[!code-csharpHOWTOWindowManagementSnippets#FirstWindowUsingCodeCODEBEHIND] [!code-vbHOWTOWindowManagementSnippets#FirstWindowUsingCodeCODEBEHIND]
Sometimes, the first instantiated xref:System.Windows.Window is not actually the main application window e.g. a splash screen. In this case, you can specify the main application window using markup, like the following:
[!code-xamlApplicationMainWindowSnippets#SetApplicationMainWindowXAML]
Whether the main window is specified automatically or manually, you can get the main window from xref:System.Windows.Application.MainWindow%2A using the following code, like the following:
[!code-csharpApplicationMainWindowSnippets#GetApplicationMainWindowCODE] [!code-vbApplicationMainWindowSnippets#GetApplicationMainWindowCODE]