* Add overview article for new WPF (#178) * Remove previous WPF .NET 5 content * Overview article * New article: Create new WPF project (#183) * Basic index file * Finish article for new project. * acro * markdown fix * Fix build errors * fix code lang * fix code lang * Add differences article for WPF (#186) * Fix VS version for create app * Add differences article * Minor * fix overview styles code * Add code langs for overview * Port Window Overview WPF article (#1011) * Add Window overview article * Add TOC * Remove temp code * Fix headers * Port final Windows related articles (#1015) * Initial test commit * Add system dialogs * 75% complete * Add images * Fix linter * Add to toc * Add more howto * Fix code * Add get/set main window * Add missing code * Add to toc * Fix warnings * Fix warnings * missing code * Update see also * fix xref * Migrate wpf net core controls-styles articles (#1023) * Migrate control-styles * Fix links * Fix links * Port databinding article. (#1022) * Migrated databinding overview * update toc * Fix links/snippets * fix links * Move to correct folder * Port initial resources docs (#1026) * initial resources docs * Build errors * Update dotnet-desktop-guide/net/wpf/systems/xaml-resources-overview.md Co-authored-by: Genevieve Warren <[email protected]> * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> * Feedback * Add app article * Add system article * Minor * meta * fix toc * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> Co-authored-by: Genevieve Warren <[email protected]> * Add xaml article * reformat redirect * Redirects * WPF update XAML article (#1031) * convert snippets * minor edits * minor * Fix warnings * Fixes #1028 * Fixes #1028 * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> * update redirects Co-authored-by: Genevieve Warren <[email protected]> * minor updates to link * Readd migration article * Warning fixes * Fix lint * Minor updates * Fix warnings for TOC/YML * last warnings Co-authored-by: Genevieve Warren <[email protected]>
3.5 KiB
title, description, ms.date, dev_langs, helpviewer_keywords
| title | description | ms.date | dev_langs | helpviewer_keywords | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to open a window | Learn about how to show a window or dialog box in Windows Foundation Presentation (WPF). You'll also learn how to handle common scenarios around managing a window or dialog box. | 03/12/2021 |
|
|
How to open a window or dialog box (WPF .NET)
You can create your own windows and display them in Windows Presentation Foundation (WPF). In this article, you'll learn how to display modal and modeless windows and dialogs.
Conceptually, a window and a dialog box are the same thing: they're displayed to a user to provide information or interaction. They're both "window" objects. The design of the window and the way it's used, is what makes a dialog box. A dialog box is generally small in size and requires the user to respond to it. For more information, see Overview of WPF windows and Dialog boxes overview.
If you're interested in opening operating system dialog boxes, see How to open a common dialog box.
Open as modal
When a modal window is opened, it generally represents a dialog box. WPF restricts interaction to the modal window, and the code that opened the window pauses until the window closes. This mechanism provides an easy way for you to prompt the user with data and wait for their response.
Use the xref:System.Windows.Window.ShowDialog%2A method to open a window. The following code instantiates the window, and opens it modally. The code opening the window pauses, waiting for the window to be closed:
:::code language="csharp" source="snippets/how-to-open-window-dialog-box/csharp/Window1.xaml.cs" id="ShowDialog"::: :::code language="vb" source="snippets/how-to-open-window-dialog-box/vb/Window1.xaml.vb" id="ShowDialog":::
Important
Once a window is closed, the same object instance can't be used to reopen the window.
For more information about how to handle the user response to a dialog box, see Dialog boxes overview: Processing the response.
Open as modeless
Opening a window modeless means displaying it as a normal window. The code that opens the window continues to run as the window becomes visible. You can focus and interact with all modeless windows displayed by your application, without restriction.
Use the xref:System.Windows.Window.Show%2A method to open a window. The following code instantiates the window, and opens it modeless. The code opening the window continues to run:
:::code language="csharp" source="snippets/how-to-open-window-dialog-box/csharp/Window1.xaml.cs" id="ShowNormal"::: :::code language="vb" source="snippets/how-to-open-window-dialog-box/vb/Window1.xaml.vb" id="ShowNormal":::
Important
Once a window is closed, the same object instance can't be used to reopen the window.
See also
- Overview of WPF windows
- Dialog boxes overview
- How to close a window or dialog box
- How to open a common dialog box
- How to open a message box
- xref:System.Windows.Window?displayProperty=fullName
- xref:System.Windows.Window.DialogResult?displayProperty=fullName
- xref:System.Windows.Window.Show?displayProperty=fullName
- xref:System.Windows.Window.ShowDialog?displayProperty=fullName