Programmatically change the Stretch and StretchDirection of content within a Viewbox
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Namespace Viewbox_Stretch_Layout_Samp
Public Partial Class Window1
Inherits Window
Public Sub stretchNone(sender As Object, e As RoutedEventArgs)
vb1.Stretch = System.Windows.Media.Stretch.None
txt1.Text = "Stretch is now set to None."
End Sub
Public Sub stretchFill(sender As Object, e As RoutedEventArgs)
vb1.Stretch = System.Windows.Media.Stretch.Fill
txt1.Text = "Stretch is now set to Fill."
End Sub
Public Sub stretchUni(sender As Object, e As RoutedEventArgs)
vb1.Stretch = System.Windows.Media.Stretch.Uniform
txt1.Text = "Stretch is now set to Uniform."
End Sub
Public Sub stretchUniFill(sender As Object, e As RoutedEventArgs)
vb1.Stretch = System.Windows.Media.Stretch.UniformToFill
txt1.Text = "Stretch is now set to UniformToFill."
End Sub
Public Sub sdUpOnly(sender As Object, e As RoutedEventArgs)
vb1.StretchDirection = System.Windows.Controls.StretchDirection.UpOnly
txt2.Text = "StretchDirection is now UpOnly."
End Sub
Public Sub sdDownOnly(sender As Object, e As RoutedEventArgs)
vb1.StretchDirection = System.Windows.Controls.StretchDirection.DownOnly
txt2.Text = "StretchDirection is now DownOnly."
End Sub
Public Sub sdBoth(sender As Object, e As RoutedEventArgs)
vb1.StretchDirection = System.Windows.Controls.StretchDirection.Both
txt2.Text = "StretchDirection is now Both."
End Sub
End Class
End Namespace