Export (0) Print
Expand All

Viewbox.StretchDirection Property

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)

'Declaration
Public Property StretchDirection As StretchDirection
<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.

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.

StretchDirection = UpOnly

StretchDirection 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.

StretchDirection = DownOnly

StretchDirection DownOnly

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

StretchDirection = Both

StretchDirection Both

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


Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft