Condividi tramite


Rectangle

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

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

<Rectangle   .../>

Properties

Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Effect (Silverlight 3), Fill (Shape), Grid.Column (Silverlight 2), Grid.ColumnSpan (Silverlight 2), Grid.Row (Silverlight 2), Grid.RowSpan (Silverlight 2), Height (UIElement), HorizontalAlignment (Silverlight 2), Margin (Silverlight 2), MaxHeight (Silverlight 2), MaxWidth (Silverlight 2), MinHeight (Silverlight 2), MinWidth (Silverlight 2), Name (DependencyObject), Opacity (UIElement), OpacityMask, Projection (Silverlight 3), RadiusX (Rectangle), RadiusY (Rectangle), RenderTransform, RenderTransformOrigin, Resources, Stretch (Shape), Stroke (Shape), StrokeDashArray, StrokeDashCap, StrokeDashOffset, StrokeEndLineCap, StrokeLineJoin, StrokeMiterLimit, StrokeStartLineCap, StrokeThickness, Style (Silverlight 2), Tag, Triggers, VerticalAlignment (Silverlight 2), Visibility, Width (UIElement)

Managed Equivalent

Rectangle

Remarks

A Rectangle object cannot support child objects. If you want a rectangular region that contains other objects, you can use a Canvas object. You can also use a composite geometry, but in this case you would probably use RectangleGeometry rather than Rectangle.

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 object, including ImageBrush or VideoBrush.

Example

The following example shows how to create a Rectangle object.

<Canvas 
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  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

Reference