Show / Hide Table of Contents

Class WindowExtensions

WinUI Window Extension Methods

Inheritance
System.Object
WindowExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
public static class WindowExtensions

Methods

| Improve this Doc View Source

CenterOnScreen(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 null if keeping the current size

System.Nullable<System.Double> height

Height of the window in device independent pixels, or null if keeping the current size

| Improve this Doc View Source

CreateFolderPicker(Window)

Creates a new instance of a FolderPicker with the provided window as a parent.

Declaration
public static FolderPicker CreateFolderPicker(this Window window)
Parameters
Type Name Description
Window window

Parent window

Returns
Type Description
FolderPicker

FolderPicker

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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
| Improve this Doc View Source

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

| Improve this Doc View Source

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

Learn more about this API from docs.microsoft.com.

| Improve this Doc View Source

GetExtendedWindowStyle(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
| Improve this Doc View Source

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

True if the overlapped presenter is on top, otherwise false.

| Improve this Doc View Source

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

True if the overlapped presenter is on maximizable, otherwise false.

| Improve this Doc View Source

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

True if the overlapped presenter is on minimizable, otherwise false.

| Improve this Doc View Source

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

True if the overlapped presenter is resizeable, otherwise false.

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was brought to the foreground.

false if the window was not brought to the foreground.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

true if this window should be maximizable.

Remarks

The presenter must be an overlapped presenter.

Exceptions
Type Condition
System.NotSupportedException

Throw if the AppWindow Presenter isn't an overlapped presenter.

| Improve this Doc View Source

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

true if this window should be minimizable.

Remarks

The presenter must be an overlapped presenter.

Exceptions
Type Condition
System.NotSupportedException

Throw if the AppWindow Presenter isn't an overlapped presenter.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

true if this window should be shown in the task switchers, otherwise false.

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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 alpha is 0, the window is completely transparent. When alpha is 255, the window is opaque.

| Improve this Doc View Source

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
| Improve this Doc View Source

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX