Rect Rect Rect Rect Rect Struct


Contains number values that represent the location and size of a rectangle.

public : struct Rect
struct winrt::Windows::Foundation::Rect
public struct Rect
Public Structure Rect
var rect = {

   height: /* Your value */,

   width: /* Your value */,

   x: /* Your value */,

   y: /* Your value */

<object property="x,y,width,height"/>
<object property="x y width height"/>


Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (introduced v1)


When applied to properties that represent UI information, the width and height values of a Rect value represent device-independent pixels. The x and y values have an indeterminate frame of reference (it depends on how this value is applied) but they often represent a point in the coordinate space of the main app window.

JavaScript In JavaScript, a Rect is an object with four data members: x, y, width, height. Other than the data members (fields), the API listed in the Rect members lists don't apply to JavaScript programming.

Notes on XAML syntax

Object attribute usage is technically permitted by the Windows Runtime XAML parsing rules. However, that usage isn't shown because it's not commonly used.

You can use a space rather than a comma as the delimiter between values. Mixed delimiter usages are also permitted.

You must specify all four values. "0,0" is not an implicit default for "x,y", and no other conventions exist that can parse less than 4 components in the string.

A Rect element cannot be declared as a resource in a XAML ResourceDictionary because Rect is not a shareable type (for more info see ResourceDictionary and XAML resource references).

Language projection and members of Rect

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic) or Visual C++ component extensions (C++/CX), then Rect has non-data members available, and its data members are exposed as read-write properties, not fields. Microsoft .NET supports this functionality through the System.Runtime.WindowsRuntime.dll interop assembly that's shipped as part of .NET for Windows Runtime app. Visual C++ component extensions (C++/CX) supports it through the language-specific platform.winmd metadata and the runtime behavior it represents.

If you are programming with C++ using the Windows Template Runtime Library (WRL), then only the data member fields exist as members of Rect, and you cannot use the utility methods or properties listed in the members table. WRL code can access similar utility methods that are available from the RectHelper static class. For more info on WRL, see WRL Integration.

Rect values and how they are interpreted by properties

Size is a similar structure that uses the same metaphor of height and width. However, a Rect specifies an origin point, whereas a Size does not. Typically Rect is used for graphics library API, and Size is used for presentation and layout in app UI, particularly for adaptive layout (where the positioning is often automatic).

The typical behavior of a Rect value when applied to properties follows these principles:

  • Width and Height cannot be negative.
  • X and Y can be negative, with the result that the Rect definition is outside the coordinate frame of reference unless there is additional translation.
  • X and Y can be 0. A value of 0 is also valid for Width or Height. (However, if a Rect with a value of 0 for either Width or Height is applied to a RectangleGeometry, the resulting RectangleGeometry does not render.)
  • X, Y, Width and Height can be non-integer values in terms of permitted values. However, you typically use integer values. XAML UI behaves best when the point locations and unit measures don't use sub-pixel values.


Height Height Height Height Height

The height of the rectangle, in pixels.

Width Width Width Width Width

The width of the rectangle, in pixels.


The x-coordinate of the upper-left corner of the rectangle.


The y-coordinate of the upper-left corner of the rectangle.

See also