Stretch property
TOC
Collapse the table of content
Expand the table of content

MediaElement.Stretch property

Gets or sets a value that describes how an MediaElement should be stretched to fill the destination rectangle.

Syntax


Public Property Stretch As Stretch


<MediaElement Stretch="stretchMemberName" />

XAML Values

stretchMemberName

A named constant of the Stretch enumeration, such as Fill.

Property value

Type: Stretch

A value of the Stretch enumeration that specifies how the source visual media is rendered. The default value is Uniform.

Remarks

Here's what the Stretch values represent for MediaElement content:

  • None: The original size of the content is preserved.
  • Fill: The content is resized to fill the destination dimensions. The aspect ratio of the video is not preserved.
  • UniformToFill: Uniformly stretches the MediaElement to fill the available layout space while preserving the aspect ratio of the content. If the aspect ratio of the destination rectangle differs from the source, the source content is clipped to fit the destination dimensions.
  • Uniform: Uniformly stretches the MediaElement to fill the layout space while preserve the aspect ratio of the image. This will ensure that the entire image is displayed, undistorted and not cropped. This may result in letterboxing or pillarboxing on the top or sides of the image, depending on the aspect ratio of the content.

Examples

Here is some code that shows how to create a zoom effect, similar to msZoom in Windows apps using JavaScript. The MediaElement content will fill up the entire layout space while preserving the aspect ratio of the content. This could result in cropping if the aspect ratio of the content is not the same as the layout space.


private void ToggleZoom(MediaElement media)
{
    if (media.Stretch != Stretch.UniformToFill)
    {
        // zoom
        media.Stretch = Stretch.UniformToFill;
    }
    else
    {
        // unzoom
        media.Stretch = Stretch.Uniform;
    }
}

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

MediaElement
Stretch
NaturalVideoHeight
NaturalVideoWidth

 

 

Show:
© 2016 Microsoft