Export (0) Print
Expand All

Shape.Stretch Property

Gets or sets a Stretch enumeration value that describes how the shape fills its allocated space.

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

public Stretch Stretch { get; set; }
<object Stretch="stretchMemberName"/>

Property Value

Type: System.Windows.Media.Stretch
One of the Stretch enumeration values. The default value at run time depends on the type of Shape.

Dependency property identifier field: StretchProperty

Generally, you do not set the Stretch value for a Shape or change it from the shape-specific default. This is because the Stretch is adjusted for each type of Shape in such a way that each Shape type's sizing and positioning properties are interpreted in the most intuitive way.

The concept of a Stretch for a Shape has to do with its natural size and how the Shape is positioned in layout. Ultimately for the layout system, all objects that render to the screen are rectangles with a width and a height. This is reflected in the presence of the properties Width and Height at the UIElement level in the object model. Some types of Shapes (Ellipse, Rectangle) can have natural sizes that are well represented by these Width and Height properties, and as a result these are the only properties you use to provide the size (although the shape that renders within that natural size is still influenced by other properties such as RadiusX). But other types of Shape such as Line or Path have other specific properties that declare the shape, and in this case the appropriate behavior is to have Width and Height be deterministic properties, calculated based on values you provide for the specific sizing properties, such as the X1, Y1, X2, Y2 of a Line. However, even for a shape like Line, Width and Height are still settable. The Stretch for a Shape influences what should happen if Width and Height are deliberately set.

For Ellipse or Rectangle, the default Stretch behavior is Fill, because their entire sizing logic is based on the Width and Height. Setting Stretch to None for an Ellipse or Rectangle effectively makes it nonrendering.

For the other shapes, the default Stretch is None . Setting Stretch to other values effectively introduces a transform, which could probably be controlled more efficiently with a true transform if that was a desired effect. See Transforms for more information on transforms.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

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

Community Additions

ADD
Show:
© 2015 Microsoft