WPF C#

    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.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace StackPanel_layout
{
  public partial class Window1 : Window
  {
        public void changeOrientation(object sender, SelectionChangedEventArgs args)
        {
            ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
            if (li.Content.ToString() == "Horizontal")
            {
        sp1.Orientation = System.Windows.Controls.Orientation.Horizontal;
            }
            else if (li.Content.ToString() == "Vertical")
            {
        sp1.Orientation = System.Windows.Controls.Orientation.Vertical;
            }
        }
        public void changeHorAlign(object sender, SelectionChangedEventArgs args)
        {
            ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
            if (li.Content.ToString() == "Left")
            {
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            }
            else if (li.Content.ToString() == "Right")
            {
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            }
            else if (li.Content.ToString() == "Center")
            {
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            }
            else if (li.Content.ToString() == "Stretch")
            {
        sp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            }
        }
        public void changeVertAlign(object sender, SelectionChangedEventArgs args)
        {
            ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
            if (li.Content.ToString() == "Top")
            {
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            }
            else if (li.Content.ToString() == "Bottom")
            {
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            }
            else if (li.Content.ToString() == "Center")
            {
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            }
            else if (li.Content.ToString() == "Stretch")
            {
        sp1.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            }
        }
        
    }
}