CSharp Programming
CSharp > Code Examples
Change StackPanel Orientation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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="240" Width="360" MinWidth="50">
<StackPanel Margin="4" Name="stackPanel1">
<Label Margin="3" HorizontalAlignment="Center">
A Button Stack
</Label>
<Button Margin="3" MaxWidth="240" MinWidth="80">Button 1</Button>
<Button Margin="3" MaxWidth="240" MinWidth="80">Button 2</Button>
<Button Margin="3" MaxWidth="240" MinWidth="80">Button 3</Button>
<Button Margin="3" MaxWidth="240" MinWidth="80">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;
}
}
}