Partilhar via


Stretch (Shape)

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

Gets or sets a value that specifies how a shape fills its allocated space.

<object Stretch="Stretch"  .../>
value = object.Stretch
object.Stretch = value

Property Value

Type: Stretch

One of the enumeration values that specifies the stretch behavior.

This property is read/write. The default value at run time depends on the type of Shape.

Managed Equivalent

Stretch

Remarks

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

The concept of a Stretch for a Shape has to do with the natural size of the Shape and how it 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 through the presence of the Width and Height properties at the UIElement level in the object model.

Some types of Shape objects (Ellipse, Rectangle) can have natural sizes that are well represented by these Width and Height properties. 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 Rectangle.RadiusX).

However, other types of Shape objects, such as Line and Path, have specific properties that declare the shape. In this case, the appropriate behavior is to have Width and Height be deterministic properties. These are calculated based on values that you provide for the specific sizing properties, such as the X1, Y1, X2, and Y2 properties of a Line. However, you can set the Width and Height properties even for a shape such as Line. The Stretch for a Shape influences what should happen if Width and Height are deliberately set.

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

For the other shapes, the default Stretch behavior is None. Setting Stretch to other values effectively introduces a transform. If this is the desired effect, the stretch behavior could probably be controlled more efficiently with a true transform.