Rect

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the upper-left corner, width, and height of a rectangle.

<object property = "X,Y,width,height" />
-or-
<object property = "X Y width height" />

rectString Grammar

X,Y,width,height

-or-

X Y width height

  • X is the horizontal (x) point position of the upper-left corner in pixels. Y is the vertical (y) point position of the upper-left corner in pixels.

  • width is the width of the Rect object in pixels.

  • height is the height of the Rect in pixels.

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

  • width and height can be negative, 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 for which the X,Y point is now the lower-left corner.

  • X and Y can be 0. 0 is also valid for width or height. If a Rect with 0 for either width or height is applied to a RectangleGeometry object, the resulting RectangleGeometry does not render.

  • X, Y, width, and height can be noninteger values in terms of permitted values.

  • You can use a space rather than a comma as the delimiter between values.

Managed Equivalent

Rect

Remarks

Do not confuse Rect and Rectangle. Rect is a common data structure that specifies rectangular regions as a single value for certain properties. However, Rect has no meaning of its own or any direct user interface (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 object is a Shape object and, therefore, a UIElement object. You can specify a Rectangle as a XAML element and instantiate a rectangular shape that is displayed in the UI and can process input events.

Rect parallels a convention that is supported by a type converter, such that properties that take a Rect as their value can specify a Rect as a formatted string. The type converter generates a new Rect value based on processing the string. The type converter functions both for XAML uses and script uses. In both cases, you supply a quoted string with delimiters between values. The format of that string, using a comma as the delimiter, is an X,Y,width,height value set. You can use a space rather than a comma as the delimiter between X Y width height in the string.

X, Y, height, and width can be noninteger values in terms of permitted values, but they are interpreted as integers regardless during type conversion. In general, you should not use noninteger values. In particular, the comma used as separator in the type converter behavior will clash with cultural uses in which the comma is the culture-specific decimal separator if that value is entered as a string.

Rect is the type that is returned from a call to the StrokeCollection.GetBounds and Stroke.GetBounds methods used for ink information capture. For these cases, Rect is returned as an object. However, you cannot set the values of this bounding Rect; its property values are for reference only.

Rect is also used as a property value in geometry-related objects (for example, the RectangleGeometry.Rect property). If you attempt to get values through scripting for geometry cases in which the value is a Rect, the GetValue method call will fail. This is because the object model does not use Rect as a true object for these particular properties, and the type conversion behavior does not provide a reverse conversion to provide a ToString or other value representation to the object model.

In scripting, it is generally true that you cannot construct a new Silverlight object. However, for types that have type converter support, you can use the type converter behavior to generate the object from a convertible input type, in this case a string. Therefore, in order to generate a Rect value in script, you must target a property that takes a Rect (for example, RectangleGeometry.Rect) and use that property's native type conversion behavior. For example, if myRectGeometry is a reference to an existing RectangleGeometry, use the following syntax:

myRectGeometry.Rect = "100,100,200,300"; //place at point 100,100, width 200 height 300

See Also

Reference