silverlight - How to change StackPanel orientation programmatically

how to set change StackPanel orientation horizontal and vertical in silverlight
MainPage.xaml

<UserControl 
    x:Class="SilverlightApps.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="600" 
    d:DesignWidth="800" 
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    >

    <Grid x:Name="LayoutRoot" Background="White">
        <Rectangle
      x:Name="Rectangle1"
      Fill="AliceBlue" 
      HorizontalAlignment="Left" 
      Height="82" 
      Margin="20,12,0,0" 
      Stroke="Black" 
      VerticalAlignment="Top" 
      Width="600"
      StrokeThickness="0"
            />

        <TextBlock 
      x:Name="TextBlock1" 
      Height="82" 
      HorizontalAlignment="Left" 
      Margin="20,9,0,0" 
      Text="how to set change StackPanel orientation horizontal and vertical in silverlight"
      VerticalAlignment="Top"
      TextWrapping="Wrap"
      FontSize="20"
      FontStyle="Italic"
      Foreground="MidnightBlue"
      Width="600"
      Padding="25,10,10,0"
            />

        <StackPanel 
      x:Name="StackPanel1"
      HorizontalAlignment="Left" 
      Height="175" 
      Margin="20,124,0,0" 
      VerticalAlignment="Top" 
      Width="542"
      Background="Khaki"
            >
            <Button
                Name="Button1"
                Content="Button1" 
                HorizontalAlignment="Left" 
                Height="31" 
                Width="121"
                Margin="10"
                />
            <Button
                Name="Button2"
                Content="Button2" 
                HorizontalAlignment="Left" 
                Height="31" 
                Width="121"
                Margin="10"
                />
            <Button
                Name="Button3"
                Content="Button3" 
                HorizontalAlignment="Left" 
                Height="31" 
                Width="121"
                Margin="10"
                />
        </StackPanel>

        <Button
            Name="Button4"
            Content="Set StackPanel Orientation Horizontal"
            HorizontalAlignment="Left"
            Height="40"
            Click="Button4_Click"
            Margin="20,313,0,247" 
            Width="235"
            VerticalAlignment="Top"
            />

        <Button
            Name="Button5"
            Content="Set StackPanel Orientation Vertical"
            HorizontalAlignment="Left"
            Height="40"
            Click="Button5_Click"
            Margin="327,313,0,247" 
            Width="235"    
            VerticalAlignment="Top"
            />
    </Grid>
</UserControl>
MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApps
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

        }

        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            StackPanel1.Orientation = Orientation.Horizontal;
        }

        private void Button5_Click(object sender, RoutedEventArgs e)
        {
            StackPanel1.Orientation = Orientation.Vertical;
        }
    }
}
More silverlight examples