public sealed record DesktopWindowBounds : IEquatable<DesktopWindowBounds> A window's frame in the platform's native window units, exactly as DesktopWindow.SetBoundsAsync takes it: DesktopWindowState.Bounds read from a window sets the same frame again, to the pixel.
Remarks
Unlike DesktopWindowState.X, DesktopWindowState.Y, DesktopWindowState.Width and DesktopWindowState.Height, which keep the units of DesktopWindow.MoveAsync and DesktopWindow.ResizeAsync (and of saved placements), all four values here use one unit, so they never round:
- Windows – Physical virtual-screen pixels: the window rectangle (
GetWindowRect), including the invisible resize borders of Windows 10 and 11.DesktopWindowBounds.Scaleis the window's DPI divided by 96, such as 1.5 at 150 %. - macOS – Points: the frame, title bar included, its top-left corner measured right and down from the top-left corner of the primary screen (as
DesktopWindowState.X).DesktopWindowBounds.Scaleis 1. - Linux, GTK 3 and GTK 4 – Logical pixels: the top-left corner of the frame and the content size, without decorations, as in
DesktopWindowState, since GTK sizes a window by its content. On WaylandDesktopWindowBounds.XandDesktopWindowBounds.Yarenull.DesktopWindowBounds.Scaleis 1.
A length in device-independent pixels (points, logical pixels), such as the width of a panel, becomes native units with DesktopWindowBounds.Scale; DesktopWindowBounds.Expand does this once, so growing a window and shrinking it by the same length returns exactly the bounds it started from. At 150 % a window 1001 pixels wide grows by 372 to 1559 pixels and shrinks back to 1001.
A custom window host (IDesktopBoundsWindowHost) defines its own units and documents them.
Constructors
DesktopWindowBounds
public DesktopWindowBounds() No documentation.
Properties
Height
public int Height { get; init; } Gets the height in native units.
Scale
public double Scale { get; init; } Gets the native units per device-independent pixel when the bounds were read: the window's DPI divided by 96 on Windows, and 1 on macOS (points) and Linux (logical pixels). Defaults to 1.
Remarks
DesktopWindowBounds.Expand uses it to convert lengths. DesktopWindow.SetBoundsAsync ignores it: native units do not depend on the scale.
Width
public int Width { get; init; } Gets the width in native units.
X
public int? X { get; init; } Gets the horizontal position of the top-left corner, or null where the platform reports no position (Wayland) or to keep the window where it is.
Remarks
Applies only together with DesktopWindowBounds.Y.
Y
public int? Y { get; init; } Gets the vertical position of the top-left corner, or null where the platform reports no position (Wayland) or to keep the window where it is.
Remarks
Applies only together with DesktopWindowBounds.X.
Methods
Expand
public DesktopWindowBounds Expand(DesktopWindowEdge edge, double length, DesktopLayoutDirection layoutDirection = (DesktopLayoutDirection)0) Returns these bounds grown on one edge by a length in device-independent pixels (points on macOS, logical pixels on Linux), or shrunk by a negative length.
Parameters
edgeThe edge that moves.
DesktopWindowEdge.LeftmovesDesktopWindowBounds.Xand changes the width, so the right edge stays where it is;DesktopWindowEdge.RightkeepsDesktopWindowBounds.X.DesktopWindowEdge.StartandDesktopWindowEdge.EndfollowlayoutDirection.lengthThe length to add to the width, converted to native units with
DesktopWindowBounds.Scaleand rounded once, half away from zero.layoutDirectionThe direction that resolves
DesktopWindowEdge.StartandDesktopWindowEdge.End, such as the window'sDesktopWindowOptions.LayoutDirection: right to left makes the start the right edge;DesktopLayoutDirection.Defaultand left to right make it the left edge.
Returns
The new bounds, with the same DesktopWindowBounds.Scale.
Exceptions
ArgumentOutOfRangeExceptionedgeorlayoutDirectionis not a defined value,lengthis not finite, or the width would not stay positive.InvalidOperationExceptionThe left edge would move but the bounds have no position (Wayland, where a window cannot be moved), or
DesktopWindowBounds.Scaleis not a positive finite number.
Remarks
A length rounds to the same number of native units whether it is added or removed, so bounds.Expand(edge, length).Expand(edge, -length) equals bounds.