A Rect specifies the upper-left corner, width, and height of a rectangle.
<object property = "X,Y,width,height" />-or-
<object property = "X Y width height" />
X Y width height
- X is the X (horizontal) point position of the top left corner in pixels. Y is the Y (vertical) point position of the top left corner in pixels.
- width is the width of the Rect 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 where the X,Y point is now the bottom left corner.
- X and Y can be zero. Zero is also valid for width or height. If a Rect with zero 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, but are interpreted as integers regardless during rendering.
- You can use a space rather than a comma as the delimiter betweeen values.
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.
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 usages and script usages. 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 and Y, and height and width, can be non-integer values in terms of permitted values, but 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 usages where the comma is the culture-specific decimal point symbol 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 (such as RectangleGeometry.Rect). If you attempt to get values through scripting for these geometry cases where the value is a Rect, the GetValue 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 cases of types that have type converter support, you can use the type converter behavior to generate the object from out of a convertible input type, in this case a string. So, in order to generate a Rect value in script, you must target a property that takes a Rect (such as RectangleGeometry.Rect) and use that property's native type conversion behavior. For instance, if
myRectGeometry is a reference to an existing RectangleGeometry, use this syntax:
myRectGeometry.Rect = "100,100,200,300"; //place at point 100,100, width 200 height 300