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.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<ViewBox Stretch = "stretchValue"/>
XAML Values
Property Value
Type: System.Windows.Media.StretchA 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.

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.

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.

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

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."; }