Rect Rect Rect Rect Struct


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

public : struct Rectpublic struct RectPublic Structure Rect// You can use this struct in JavaScript.
<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:


Height Height Height Height

The height of the rectangle, in pixels.

public : field float Heightpublic field float HeightPublic Field Height// You can use this field in JavaScript.

Width Width Width Width

The width of the rectangle, in pixels.

public : field float Widthpublic field float WidthPublic Field Width// You can use this field in JavaScript.


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

public : field float Xpublic field float XPublic Field X// You can use this field in JavaScript.


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

public : field float Ypublic field float YPublic Field Y// You can use this field in JavaScript.