Window
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
is a top-level .
You will not usually create instances of the Window
class directly; instead the Window
class is usually sub-classed for each type of window to be shown by an application. For information on how to create new window classes from templates see the .
Title
The window title
Icon
The window icon
SizeToContent
Describes the window's auto-sizing behavior
WindowState
The minimized/maximized state of the window
The main window is the window passed to ApplicationLifetime.MainWindow
in the OnFrameworkInitializationCompleted
method of your your App.axaml.cs
file:
It can be retrieved at any time by casting Application.ApplicationLifetime
IClassicDesktopStyleApplicationLifetime.
You can show a window using the Show
method:
Windows can be closed using the Close
method. This has the same effect as when a user clicks the window's close button:
Note that once a window has been closed, it cannot be shown again. If you want to re-show the window then you should use the Hide
method:
You can show a window as a modal dialog by calling the ShowDialog
method. ShowDialog
requires an owner window to be passed:
The ShowDialog
method will return immediately. If you want to wait for the dialog to be closed, you can await
the call:
Dialogs can return a result by calling the Close
method with an object. This result can then be read by the caller of ShowDialog
. For example:
A window can be prevented from closing by handling the Closing
event and setting e.Cancel = true
:
You could also hide the window instead. This allows the window to be re-shown after the user clicks the close button:
See also