Sdílet prostřednictvím


Shape.StrokeDashArray Property

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

Gets or sets a collection of Double values that indicate the pattern of dashes and gaps that is used to outline shapes.

Namespace:  System.Windows.Shapes
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property StrokeDashArray As DoubleCollection
public DoubleCollection StrokeDashArray { get; set; }
<object StrokeDashArray="strokeDashString"/>

XAML Values

  • strokeDashString
    See "XAML Grammar" in Remarks.

Property Value

Type: System.Windows.Media.DoubleCollection
A collection of Double values that specify the pattern of dashes and gaps.

Remarks

Dependency property identifier field: StrokeDashArrayProperty

Each Double in the collection specifies the length of a dash or gap relative to the Thickness of the pen. For example, a value of 1 creates a dash or gap that has the same length as the thickness of the pen (a square).

The first item in the collection, which is located at index 0, specifies the length of a dash; the second item, which is located at index 1, specifies the length of a gap.

Objects with an even index value specify dashes; objects with an odd index value specify gaps.

Generally you should use integral numeric values. Nonintegral values can cause subpixel rendering, and may alter the apparent color of the stroke.

XAML Grammar

A valid strokeDashString for the StrokeDashArray property describes one or more strokes with gaps between each stroke, where odd numbered entries in the string sequence describe the strokes and even numbered entries describe the gaps. The measurement of these is in pixels. As an example of the strokeDashString grammar, the string "2 1" would produce a repeating sequence of 2-pixel length strokes with single pixel gaps between each stroke.

S[,G][,S*,G**]*

S

A value that defines the length of the first stroke in the sequence.

G

A value that defines the length of the first gap between strokes in the sequence. If G is omitted, the gap length is identical to the preceding stroke length.

S*

A value that defines the length of the additional strokes in the sequence.

G*

A value that defines the length of additional gaps between strokes in the sequence. If G* is omitted, the gap length is identical to the preceding stroke length.

  • The [] characters are not literals, they are indicators of optional values. The * indicates that any number of stroke-dash pairs beyond the initial S,G is permitted.

  • The separator in this grammar can be either a space or a comma. You can use a mixture of space and comma as separators.

  • Each value in the string specifies the length of a stroke or gap relative to the thickness of the pen as a factor. For example, a value of 1 creates a dash or gap that has the same length as the thickness of the pen (a square).

  • If an odd-numbered total of entries is in the string, then the missing even-numbered entry of a pair will use the gap value specified by the last valid (even-numbered entry) gap value.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.