Viewbox.StretchDirection Property
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Gets or sets the StretchDirection, which determines how scaling is applied to the contents of a Viewbox.
Namespace: System.Windows.Controls
Assembly: System.Windows (in System.Windows.dll)
Syntax
'Declaration
Public Property StretchDirection As StretchDirection
public StretchDirection StretchDirection { get; set; }
<ViewBox StretchDirection = "stretchDirectionValue"/>
XAML Values
- stretchDirectionValue
A named constant of the StretchDirection enumeration, such as Both
Property Value
Type: System.Windows.Controls.StretchDirection
A StretchDirection, which determines how scaling is applied to the contents of a Viewbox. The default is Both.
Remarks
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.
Examples
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 Sub sdUpOnly(ByVal sender As Object, ByVal e As RoutedEventArgs)
vb1.StretchDirection = StretchDirection.UpOnly
vb2.StretchDirection = StretchDirection.UpOnly
vb3.StretchDirection = StretchDirection.UpOnly
txt2.Text = "StretchDirection is now UpOnly."
End Sub
'Setting the StretchDirection property to DownOnly
Private Sub sdDownOnly(ByVal sender As Object, ByVal e As RoutedEventArgs)
vb1.StretchDirection = StretchDirection.DownOnly
vb2.StretchDirection = StretchDirection.DownOnly
vb3.StretchDirection = StretchDirection.DownOnly
txt2.Text = "StretchDirection is now DownOnly."
End Sub
'Setting the StretchDirection property to Both
Private Sub sdBoth(ByVal sender As Object, ByVal e As RoutedEventArgs)
vb1.StretchDirection = StretchDirection.Both
vb2.StretchDirection = StretchDirection.Both
vb3.StretchDirection = StretchDirection.Both
txt2.Text = "StretchDirection is now Both."
End Sub
//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.";
}
Version Information
Silverlight
Supported in: 5, 4
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.