Share via


Rectangle Object

Draws a rectangle shape, which can have a stroke and a fill.

XAML
<Rectangle .../>
Scripting
To create an object using scripting, see CreateFromXAML.

Properties

Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Fill, Height, Name, Opacity, OpacityMask, RadiusX, RadiusY, RenderTransform, RenderTransformOrigin, Resources, Stretch, Stroke, StrokeDashArray, StrokeDashCap, StrokeDashOffset, StrokeEndLineCap, StrokeLineJoin, StrokeMiterLimit, StrokeStartLineCap, StrokeThickness, Tag, Triggers, Width

Methods

AddEventListener, CaptureMouse, Equals, FindName, GetHost, GetParent, GetValue, ReleaseMouseCapture, RemoveEventListener, SetValue

Events

Loaded, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove

Remarks

A Rectangle cannot support child objects. If you want a rectangular region that contains other objects, you can use a Canvas. You can also use a composite geometry, but in this case you would probably use RectangleGeometry rather than Rectangle. For details about how to create composite geometries, see Silverlight Geometries Overview.

The fill for a Rectangle or any other shape that has a fill area does not have to be a solid color. It can be any Brush, including ImageBrush or VideoBrush.

Examples

The following example shows how to create a Rectangle.

XAML
<Canvas 
  xmlns="https://schemas.microsoft.com/client/2007" 
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">  
                   
  <Rectangle Width="100" Height="100" Fill="Blue" Stroke="Red" 
   Canvas.Top="20" Canvas.Left="20" StrokeThickness="3" />
</Canvas>

See Also

Shapes Overview
Shape