WPF VB.Net Tutorial

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="StackPanel_layout.Window1"
    Title="StackPanel Sample">
  
        
          
            
          

          
            
            
          

                Change StackPanel Orientation:
                Change HorizontalAlignment:
                Change VerticalAlignment:
                
                    Horizontal
                    Vertical
                
                
                    Left
                    Right
                    Center
                    Stretch
                
                
                    Top
                    Bottom
                    Center
                    Stretch
                
          
                
                
                
                
                
                
          
        
  

//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Namespace StackPanel_layout
  Public Partial Class Window1
    Inherits Window
    Public Sub changeOrientation(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      If li.Content.ToString() = "Horizontal" Then
        sp1.Orientation = System.Windows.Controls.Orientation.Horizontal
      ElseIf li.Content.ToString() = "Vertical" Then
        sp1.Orientation = System.Windows.Controls.Orientation.Vertical
      End If
    End Sub
    Public Sub changeHorAlign(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      If li.Content.ToString() = "Left" Then
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left
      ElseIf li.Content.ToString() = "Right" Then
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Right
      ElseIf li.Content.ToString() = "Center" Then
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center
      ElseIf li.Content.ToString() = "Stretch" Then
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
      End If
    End Sub
    Public Sub changeVertAlign(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      If li.Content.ToString() = "Top" Then
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Top
      ElseIf li.Content.ToString() = "Bottom" Then
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Bottom
      ElseIf li.Content.ToString() = "Center" Then
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Center
      ElseIf li.Content.ToString() = "Stretch" Then
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Stretch
      End If
    End Sub
  End Class
End Namespace