Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Shape.Stroke Property

Gets or sets the Brush that specifies how to paint the Shape outline.

Namespace: System.Windows.Shapes
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public Brush Stroke { get; set; }
/** @property */
public Brush get_Stroke ()

/** @property */
public void set_Stroke (Brush value)

public function get Stroke () : Brush

public function set Stroke (value : Brush)

For XAML information, see the Brush type.

Property Value

A Brush that specifies how the Shape outline is painted. The default is a null reference (Nothing in Visual Basic).

This example shows how to draw a rectangle by using the Rectangle element.

To draw a rectangle, create a Rectangle element and specify its Width and Height. To paint the inside of the rectangle, set its Fill. To give the rectangle an outline, use its Stroke and StrokeThickness properties.

To give the rectangle rounded corners, specify the optional RadiusX and RadiusY properties. The RadiusX and RadiusY 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 Rectangle elements are drawn in a Canvas. The first rectangle has a Blue interior. The second rectangle has a Blue interior, a Black outline, and rounded corners.

  <Canvas Width="120" Height="200" >

  <!-- Draws a 100 by 50 rectangle with a solid blue fill. -->
    Canvas.Top="25" />

  <!-- Draws a 100 by 50 rectangle with a solid blue fill,
       a black outline, and rounded corners. -->
    Stroke="Black" StrokeThickness="4"
    RadiusX="20" RadiusY="20"


Although this example uses a Canvas to contain the rectangles, you can use rectangle elements (and all the other shape elements) with any Panel or Control that supports non-text content. In fact, rectangles are particularly useful for providing backgrounds for portions of Grid panels. For an example, see the Table Overview.

This example is part of a larger sample; for the complete sample, see Shape Elements Sample.

More Code

How to: Make a UIElement Transparent or Semi-Transparent

This example shows how to make a UIElement transparent or semi-transparent. To make an element transparent or semi-transparent, you set its Opacity property. A value of 0.0 makes the element completely transparent, while a value of 1.0 makes the element completely opaque. A value of 0.5 makes the element 50% opaque, and so on. An element's Opacity is set to 1.0 by default.

How to: Paint an Area with an Image

This example shows how to use the ImageBrush class to paint an area by using an image. An ImageBrush displays a single image, which is specified by its ImageSource property.

How to: Animate a Property Without Using a Storyboard

This example shows one way to apply an animation to a property without using a Storyboard.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2017 Microsoft