Stretch Property
Collapse the table of content
Expand the table of content

Viewbox.Stretch Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the Stretch mode, which determines how content fits into the available space.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Stretch Stretch { get; set; }
<ViewBox Stretch = "stretchValue"/>

XAML Values

stretchValue

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

Property Value

Type: System.Windows.Media.Stretch
A Stretch mode, which determines how content fits in the available space. The default is Uniform.

If you set the Stretch property to None, the content preserves its original size.

Stretch = None

ViewBox Stretch None

If you set the Stretch property to Uniform, the image is resized to fit the Viewbox. The Viewbox takes as much space as needed to show the entire image, while preserving the aspect ratio.

Stretch = Uniform

ViewBox Stretch Uniform

If you set the Stretch property to UniformToFill, the image is resized to fill the destination dimensions, while preserving its native aspect ratio. If the aspect ratio of the destination rectangle differs from the source, the source content is clipped to fit in the destination dimensions.

Stretch = UniformToFill

ViewBox Stretch UniformToFill

If you set the Stretch property to Fill, the image fills the entire space, but does not preserve the aspect ratio.

Stretch = Fill

ViewBox Stretch Fill

The following example shows how you can set the Stretch properties in C# and Visual Basic. This example is a part of a larger example available in the Viewbox class overview.


//Setting the Stretch property to None
private void stretchNone(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.None;
    vb2.Stretch = Stretch.None;
    vb3.Stretch = Stretch.None;
    txt1.Text = "Stretch is now set to None.";
}

//Setting the Stretch property to Fill
private void stretchFill(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.Fill;
    vb2.Stretch = Stretch.Fill;
    vb3.Stretch = Stretch.Fill;
    txt1.Text = "Stretch is now set to Fill.";
}

//Setting the Stretch property to Uniform
private void stretchUni(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.Uniform;
    vb2.Stretch = Stretch.Uniform;
    vb3.Stretch = Stretch.Uniform;
    txt1.Text = "Stretch is now set to Uniform.";
}

//Setting the Stretch property to UniformToFill
private void stretchUniFill(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.UniformToFill;
    vb2.Stretch = Stretch.UniformToFill;
    vb3.Stretch = Stretch.UniformToFill;
    txt1.Text = "Stretch is now set to UniformToFill.";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft