Change StackPanel Orientation : StackPanel « Windows Presentation Foundation « C# / C Sharp






Change StackPanel Orientation

Change StackPanel Orientation
  


<Window x:Class="LayoutPanels.SimpleStack"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SimpleStack" Height="223" Width="354" MinWidth="50">
  <StackPanel Margin="3" Name="stackPanel1">
    <Label Margin="3" HorizontalAlignment="Center">
      A Button Stack
    </Label>
    <Button Margin="3" MaxWidth="200" MinWidth="100">Button 1</Button>
    <Button Margin="3" MaxWidth="200" MinWidth="100">Button 2</Button>
    <Button Margin="3" MaxWidth="200" MinWidth="100">Button 3</Button>
    <Button Margin="3" MaxWidth="200" MinWidth="100">Button 4</Button>

    <CheckBox Name="chkVertical" Margin="10" HorizontalAlignment="Center"
     Checked="chkVertical_Checked" Unchecked="chkVertical_Unchecked">
      Use Vertical Orientation</CheckBox>            
  </StackPanel>
</Window>



//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LayoutPanels
{
    public partial class SimpleStack : Window
    {

        public SimpleStack()
        {
            InitializeComponent();
        }

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

        private void chkVertical_Unchecked(object sender, RoutedEventArgs e)
        {
            stackPanel1.Orientation = Orientation.Vertical;
        }
    }
}

   
    
  








Related examples in the same category

1.Stretch = Uniform
2.Stretch = UniformToFill
3.Stretch = FillStretch = Fill
4.Stretch = NoneStretch = None
5.StackPanel with StackPanelStackPanel with StackPanel
6.Simple StackPanelSimple StackPanel
7.Set height, Background and Orientation for StackPanelSet height, Background and Orientation for StackPanel
8.Use the methods that are defined by the IScrollInfo interface to scroll the child content of a StackPanel.Use the methods that are defined by the IScrollInfo interface to scroll the child content of a StackPanel.
9.Use StackPanel to arrange child objects in a single line that you can align horizontally or vertically.Use StackPanel to arrange child objects in a single line that you can align horizontally or vertically.