--- title: "How to: Draw a Rectangle" ms.date: "03/30/2017" helpviewer_keywords: - "drawing [WPF], rectangles" - "graphics [WPF], rectangles" - "rectangles [WPF], drawing" ms.assetid: beeb57ef-fab5-4446-a38a-1588f97b4c2f --- # How to: Draw a Rectangle This example shows how to draw a rectangle by using the element. To draw a rectangle, create a element and specify its and . To paint the inside of the rectangle, set its . To give the rectangle an outline, use its and properties. To give the rectangle rounded corners, specify the optional and properties. The and properties set the x-axis and y-axis radii of the ellipse that is used to round the corners of the rectangle. In the following example, two elements are drawn in a . The first rectangle has a interior. The second rectangle has a interior, a outline, and rounded corners. ## Example [!code-xaml[drawingwithshapeelements#Rectangle1](~/samples/snippets/csharp/VS_Snippets_Wpf/DrawingWithShapeElements/CS/rectangleexample.xaml#rectangle1)] Although this example uses a to contain the rectangles, you can use rectangle elements (and all the other shape elements) with any or that supports non-text content. In fact, rectangles are particularly useful for providing backgrounds for portions of panels. For an example, see the [Table Overview](../advanced/table-overview.md). This example is part of a larger sample; for the complete sample, see [Shape Elements Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Graphics/ShapeElements). ## See also - - [Shape Elements Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Graphics/ShapeElements) - [Shapes and Basic Drawing in WPF Overview](shapes-and-basic-drawing-in-wpf-overview.md) - [Table Overview](../advanced/table-overview.md)