Class WindowExtensions
WinUI Window Extension Methods
Inheritance
Inherited Members
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
public static class WindowExtensions
Methods
| Improve this Doc View SourceCenterOnScreen(UI.Xaml.Window, Nullable<Double>, Nullable<Double>)
Centers the window on the current monitor
Declaration
public static void CenterOnScreen(this UI.Xaml.Window window, double? width = null, double? height = null)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Nullable<System.Double> | width | Width of the window in device independent pixels, or |
System.Nullable<System.Double> | height | Height of the window in device independent pixels, or |
CreateMessageDialog(Window, String, String)
Initializes a new instance of the MessageDialog class with the provided window as a parent to display a titled message dialog that can be used to ask your user simple questions.
Declaration
public static UI.Popups.MessageDialog CreateMessageDialog(this Window window, string content, string title = "")
Parameters
Type | Name | Description |
---|---|---|
Window | window | Parent window |
System.String | content | The message displayed to the user. |
System.String | title | The title you want displayed on the dialog. |
Returns
Type | Description |
---|---|
Windows.UI.Popups.MessageDialog | Message dialog |
CreateOpenFilePicker(Window)
Creates a new instance of a FileOpenPicker with the provided window as a parent.
Declaration
public static FileOpenPicker CreateOpenFilePicker(this Window window)
Parameters
Type | Name | Description |
---|---|---|
Window | window | Parent window |
Returns
Type | Description |
---|---|
FileOpenPicker | FileOpenPicker |
CreateSaveFilePicker(Window)
Creates a new instance of a FileSavePicker with the provided window as a parent.
Declaration
public static FileSavePicker CreateSaveFilePicker(this Window window)
Parameters
Type | Name | Description |
---|---|---|
Window | window | Parent window |
Returns
Type | Description |
---|---|
FileSavePicker | SaveFilePicker |
GetAppWindow(UI.Xaml.Window)
Gets the AppWindow from the handle
Declaration
[Obsolete("Use Microsoft.UI.Xaml.Window.AppWindow")]
public static AppWindow GetAppWindow(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window |
Returns
Type | Description |
---|---|
AppWindow |
GetAppWindowFromWindowHandle(IntPtr)
Gets the AppWindow from an HWND
Declaration
public static AppWindow GetAppWindowFromWindowHandle(IntPtr hwnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd |
Returns
Type | Description |
---|---|
AppWindow | AppWindow |
GetDpiForWindow(UI.Xaml.Window)
Returns the dots per inch (dpi) value for the associated window.
Declaration
public static uint GetDpiForWindow(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | The window you want to get information about. |
Returns
Type | Description |
---|---|
System.UInt32 | The DPI for the window which depends on the DPI_AWARENESS of the window. See the Remarks for more information. An invalid hwnd value will result in a return value of 0. |
Remarks
| Improve this Doc View SourceGetExtendedWindowStyle(UI.Xaml.Window)
Gets the current window style
Declaration
public static ExtendedWindowStyle GetExtendedWindowStyle(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Returns
Type | Description |
---|---|
ExtendedWindowStyle |
GetIsAlwaysOnTop(UI.Xaml.Window)
Gets a value indicating whether this window is on top or not.
Declaration
public static bool GetIsAlwaysOnTop(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetIsMaximizable(UI.Xaml.Window)
Gets a value indicating whether this window is maximizeable or not.
Declaration
public static bool GetIsMaximizable(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetIsMinimizable(UI.Xaml.Window)
Gets a value indicating whether this window is minimizeable or not.
Declaration
public static bool GetIsMinimizable(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetIsResizable(UI.Xaml.Window)
Gets a value indicating whether this resizable or not.
Declaration
public static bool GetIsResizable(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetWindowHandle(UI.Xaml.Window)
Gets the native HWND pointer handle for the window
Declaration
public static IntPtr GetWindowHandle(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | The window to return the handle for |
Returns
Type | Description |
---|---|
System.IntPtr | HWND handle |
GetWindowHandle(WindowId)
Gets the window HWND handle from a Window ID.
Declaration
public static IntPtr GetWindowHandle(this WindowId windowId)
Parameters
Type | Name | Description |
---|---|---|
WindowId | windowId | Window ID to get handle from |
Returns
Type | Description |
---|---|
System.IntPtr | Window HWND handle |
GetWindowStyle(UI.Xaml.Window)
Gets the current window style
Declaration
public static WindowStyle GetWindowStyle(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Returns
Type | Description |
---|---|
WindowStyle |
Hide(UI.Xaml.Window)
Hides the window and activates another window.
Declaration
public static bool Hide(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Returns
Type | Description |
---|---|
System.Boolean |
|
Maximize(UI.Xaml.Window)
Maximizes the specified window.
Declaration
public static void Maximize(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
Minimize(UI.Xaml.Window)
Minimizes the specified window and activates the next top-level window in the Z order.
Declaration
public static void Minimize(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
Move(UI.Xaml.Window, Int32, Int32)
Positions the window
Declaration
public static void Move(this UI.Xaml.Window window, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Int32 | x | Left side of the window |
System.Int32 | y | Top side of the window |
MoveAndResize(UI.Xaml.Window, Double, Double, Double, Double)
Positions and resizes the window
Declaration
public static void MoveAndResize(this UI.Xaml.Window window, double x, double y, double width, double height)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Double | x | Left side of the window |
System.Double | y | Top side of the window |
System.Double | width | Width of the window in device independent pixels. |
System.Double | height | Height of the window in device independent pixels. |
Restore(UI.Xaml.Window)
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position.
Declaration
public static void Restore(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
SetExtendedWindowStyle(UI.Xaml.Window, ExtendedWindowStyle)
Sets the current window style
Declaration
public static void SetExtendedWindowStyle(this UI.Xaml.Window window, ExtendedWindowStyle newStyle)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
ExtendedWindowStyle | newStyle |
SetForegroundWindow(UI.Xaml.Window)
Brings the thread that created the specified window into the foreground and activates the window.
Declaration
public static bool SetForegroundWindow(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | The window that should be activated and brought to the foreground. |
Returns
Type | Description |
---|---|
System.Boolean |
|
SetIcon(UI.Xaml.Window, IconId)
Sets the icon for the window, using the specified icon ID.
Declaration
public static void SetIcon(this UI.Xaml.Window window, IconId iconId)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
IconId | iconId | The ID of the icon. |
SetIcon(UI.Xaml.Window, String)
Sets the icon for the window, using the specified icon path.
Declaration
public static void SetIcon(this UI.Xaml.Window window, string iconPath)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.String | iconPath | The path of the icon. |
SetIsAlwaysOnTop(UI.Xaml.Window, Boolean)
Configures whether the window should always be displayed on top of other windows or not
Declaration
public static void SetIsAlwaysOnTop(this UI.Xaml.Window window, bool enable)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Boolean | enable | Whether to display on top |
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
SetIsMaximizable(UI.Xaml.Window, Boolean)
Declaration
public static void SetIsMaximizable(this UI.Xaml.Window window, bool enable)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
System.Boolean | enable |
|
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
SetIsMinimizable(UI.Xaml.Window, Boolean)
Declaration
public static void SetIsMinimizable(this UI.Xaml.Window window, bool enable)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
System.Boolean | enable |
|
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
SetIsResizable(UI.Xaml.Window, Boolean)
Enables or disables the ability to resize the window.
Declaration
public static void SetIsResizable(this UI.Xaml.Window window, bool enable)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | |
System.Boolean | enable |
Remarks
The presenter must be an overlapped presenter.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Throw if the AppWindow Presenter isn't an overlapped presenter. |
SetIsShownInSwitchers(UI.Xaml.Window, Boolean)
Enables or disables showing the window in the task switchers.
Declaration
public static void SetIsShownInSwitchers(this UI.Xaml.Window window, bool enable)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
System.Boolean | enable |
|
SetTaskBarIcon(UI.Xaml.Window, Icon)
Sets the task bar icon to the provided icon
Declaration
public static void SetTaskBarIcon(this UI.Xaml.Window window, Icon icon)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Icon | icon | Icon |
SetTitleBarBackgroundColors(UI.Xaml.Window, UI.Color)
Gets the background color for the title bar and all its buttons and their states.
Declaration
public static void SetTitleBarBackgroundColors(this UI.Xaml.Window window, UI.Color color)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
Windows.UI.Color | color | color |
SetWindowOpacity(UI.Xaml.Window, Byte)
Sets the opacity of a layered window.
Declaration
public static void SetWindowOpacity(this UI.Xaml.Window window, byte alpha)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | window |
System.Byte | alpha | Alpha value used to describe the opacity of the layered window. When |
SetWindowPresenter(UI.Xaml.Window, AppWindowPresenterKind)
Sets the window presenter kind used.
Declaration
public static void SetWindowPresenter(this UI.Xaml.Window window, AppWindowPresenterKind kind)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | |
AppWindowPresenterKind | kind |
SetWindowSize(UI.Xaml.Window, Double, Double)
Sets the width and height of the window in device-independent pixels.
Declaration
public static void SetWindowSize(this UI.Xaml.Window window, double width, double height)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window to set the size for. |
System.Double | width | Width of the window in device-independent units. |
System.Double | height | Height of the window in device-independent units. |
SetWindowStyle(UI.Xaml.Window, WindowStyle)
Sets the current window style
Declaration
public static void SetWindowStyle(this UI.Xaml.Window window, WindowStyle newStyle)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
WindowStyle | newStyle |
Show(UI.Xaml.Window)
Activates the window and displays it in its current size and position.
Declaration
public static bool Show(this UI.Xaml.Window window)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
Returns
Type | Description |
---|---|
System.Boolean |
|
ToggleExtendedWindowStyle(UI.Xaml.Window, Boolean, ExtendedWindowStyle)
Disables or enables the window style
Declaration
public static void ToggleExtendedWindowStyle(this UI.Xaml.Window window, bool visible, ExtendedWindowStyle style)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Boolean | visible | |
ExtendedWindowStyle | style |
ToggleWindowStyle(UI.Xaml.Window, Boolean, WindowStyle)
Disables or enables the window style
Declaration
public static void ToggleWindowStyle(this UI.Xaml.Window window, bool visible, WindowStyle style)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.UI.Xaml.Window | window | Window |
System.Boolean | visible | |
WindowStyle | style |