Viewbox.StretchDirection Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the StretchDirection, which determines how scaling is applied to the contents of a Viewbox.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<ViewBox StretchDirection = "stretchDirectionValue"/>
XAML Values
Property Value
Type: System.Windows.Controls.StretchDirectionA StretchDirection, which determines how scaling is applied to the contents of a Viewbox. The default is Both.
Use this property to prevent the contents of a Viewbox from being smaller or larger than its original size.
If you set the StretchDirection of the Viewbox to UpOnly, the Viewbox only enlarges its contents. The following image shows a Viewbox control with its StretchDirection set to UpOnly.

If you set the StretchDirection of the Viewbox to DownOnly, the Viewbox only shrinks its contents. The following image shows a Viewbox control with its StretchDirection set to DownOnly.

If you set the StretchDirection to Both, the Viewbox can shrink or enlarge its contents.

The following example shows how you can set the StretchDirection properties in C# and Visual Basic. This example is a part of a larger example available in the Viewbox class overview.
//Setting the StretchDirection property to UpOnly private void sdUpOnly(object sender, RoutedEventArgs e) { vb1.StretchDirection = StretchDirection.UpOnly; vb2.StretchDirection = StretchDirection.UpOnly; vb3.StretchDirection = StretchDirection.UpOnly; txt2.Text = "StretchDirection is now UpOnly."; } //Setting the StretchDirection property to DownOnly private void sdDownOnly(object sender, RoutedEventArgs e) { vb1.StretchDirection = StretchDirection.DownOnly; vb2.StretchDirection = StretchDirection.DownOnly; vb3.StretchDirection = StretchDirection.DownOnly; txt2.Text = "StretchDirection is now DownOnly."; } //Setting the StretchDirection property to Both private void sdBoth(object sender, RoutedEventArgs e) { vb1.StretchDirection = StretchDirection.Both; vb2.StretchDirection = StretchDirection.Both; vb3.StretchDirection = StretchDirection.Both; txt2.Text = "StretchDirection is now Both."; }