Export (0) Print
Expand All

Rect Structure

Describes the width, height, and point origin of a rectangle.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public struct Rect : IFormattable
<Rect ...>x,y,width,height</Rect>
<object property="x,y,width,height"/>

XAML Values

x

The x-coordinate location of the left side of the rectangle.

y

The y-coordinate location of the top side of the rectangle.

width

A value that represents the Width of the rectangle.

height

A value that represents the Height of the rectangle.

  • 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 four values in the string.

  • X and Y can be negative. width, and height can be negative and will invert the direction that width, and height are applied in rendering. See Remarks.

The Rect type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneRect(Point, Point)Initializes a Rect structure that is exactly large enough to contain the two specified points.
Public methodSupported by Silverlight for Windows PhoneRect(Point, Size)Initializes a Rect structure based on an origin and size.
Public methodSupported by Silverlight for Windows PhoneRect(Double, Double, Double, Double)Initializes a Rect structure that has the specified x-coordinate, y-coordinate, width, and height.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneBottomGets the y-axis value of the bottom of the rectangle.
Public propertyStatic memberSupported by Silverlight for Windows PhoneEmptyGets a special value that represents a rectangle with no position or area.
Public propertySupported by Silverlight for Windows PhoneHeightGets or sets the height of the rectangle.
Public propertySupported by Silverlight for Windows PhoneIsEmptyGets a value that indicates whether the rectangle is the Empty rectangle.
Public propertySupported by Silverlight for Windows PhoneLeftGets the x-axis value of the left side of the rectangle.
Public propertySupported by Silverlight for Windows PhoneRightGets the x-axis value of the right side of the rectangle.
Public propertySupported by Silverlight for Windows PhoneTopGets the y-axis position of the top of the rectangle.
Public propertySupported by Silverlight for Windows PhoneWidthGets or sets the width of the rectangle.
Public propertySupported by Silverlight for Windows PhoneXGets or sets the x-axis value of the left side of the rectangle.
Public propertySupported by Silverlight for Windows PhoneYGets or sets the y-axis value of the top side of the rectangle.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneContainsIndicates whether the rectangle described by the Rect contains the specified point.
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Indicates whether the specified object is equal to the current Rect. (Overrides ValueType.Equals(Object).)
Public methodSupported by Silverlight for Windows PhoneEquals(Rect)Indicates whether the specified Rect is equal to the current Rect.
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeCreates a hash code for the Rect. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneIntersectFinds the intersection of the rectangle represented by the current Rect and the rectangle represented by the specified Rect, and stores the result as the current Rect.
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneToString()Returns a string representation of the Rect structure. (Overrides ValueType.ToString().)
Public methodSupported by Silverlight for Windows PhoneToString(IFormatProvider)Returns a string representation of the rectangle by using the specified format provider.
Public methodSupported by Silverlight for Windows PhoneUnion(Point)Expands the rectangle represented by the current Rect exactly enough to contain the specified point.
Public methodSupported by Silverlight for Windows PhoneUnion(Rect)Expands the rectangle represented by the current Rect exactly enough to contain the specified rectangle.
Top

  NameDescription
Public operatorStatic memberSupported by Silverlight for Windows PhoneEqualityCompares two Rect structures for equality.
Public operatorStatic memberSupported by Silverlight for Windows PhoneInequalityCompares two Rect structures for inequality.
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneIFormattable.ToStringInfrastructure. For a description of this member, see ToString.
Top

Size is a similar structure that uses the same metaphor of specifying a height and width. However, a Rect specifies an origin point, whereas a Size does not. In general, Rect is used for APIs that relate to graphical presentation, and Size is used for APIs that relate to UI presentation and layout.

Do not confuse Rect and Rectangle. Rect is a common data structure that is used to specify rectangular regions as a single value for certain properties. But Rect has no meaning of its own or any direct UI connotation. The meaning of a Rect is entirely dependent on how it is handled as a value for a particular property. In contrast, a Rectangle is a Shape and therefore a UIElement. A Rectangle can be specified as a XAML element and instantiates a rectangular shape that is displayed in the UI and can process input events.

The programmatic upper limit for values is not PositiveInfinity, it is a lower number (approximately 1,000,000) that is enforced by the Silverlight native code.

Although the type of the property values of a Rect is Double, you generally should use integer values. For more information, see Layout Rounding.

Properties of Rect do not support an attribute syntax in XAML for Silverlight. In XAML you should always specify Rect-type properties through one of the following usages:

  • The XAML attribute usage, which infers properties that use the Rect type and uses a type converter to process the attribute string into the specific values for the Rect.

  • A property element usage, containing a Rect object element. For that object element, set the Rect properties using initialization text, as shown in the XAML Object Element Usage.

If you specify a Rect for use as a resource, use the object element usage and set the Rect properties using initialization text.

NoteNote:

width and height can be negative if they are specified in XAML as part of the attribute string, with the result that the direction that the width or height applies to is inverted. For instance, a height of -20 will produce a Rect where the X,Y point is now the bottom left corner. However, the Rect constructor in the managed API does not permit negative values for width and height. You should adjust the coordinate reference of x,y, width and height such that the Rect can be specified using non-negative width and height values.

The following notes on Rect values apply for a Rect that is created in XAML as well as a Rect that is constructed in code.

  • X and Y can be negative, with the result that the Rect definition is off the screen, unless there is additional translation.

  • X and Y can be 0. A value of 0 is also valid for width or height. 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.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft