Stretch Property

MediaElement.Stretch Property


Gets or sets a Stretch value that describes how a MediaElement fills the destination rectangle.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public Stretch Stretch { get; set; }

Property Value

Type: System.Windows.Media.Stretch

The stretch value for the rendered media. The default is Uniform.

The following illustration demonstrates the different Stretch values.

Different TileBrush Stretch settings

Different gradient spread methods

Identifier field


Metadata properties set to true


The following example shows how to create a Viewbox and set the Stretch mode of content.

// Create a Viewbox and add it to the Canvas
myViewbox = new Viewbox();
myViewbox.StretchDirection = StretchDirection.Both;
myViewbox.Stretch = Stretch.Fill;
myViewbox.MaxWidth = 400;
myViewbox.MaxHeight = 400;

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft