<Window x:Class="VerticalGridColumns.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:VerticalGridColumns"
Title="Pivoted Grid" Height="300" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="PersonsProvider" ObjectType="{x:Type data:Persons}" />
<ControlTemplate x:Key="HeaderButtonTemplate" TargetType="{x:Type Button}">
<Border Width="auto"
Height="auto"
BorderThickness="1"
BorderBrush="Gray"
Padding="10,3,10,3"
Background="Gainsboro">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
<DataTemplate x:Key="MyDataTemplate">
<Border BorderThickness="1" BorderBrush="Gray">
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="auto" SharedSizeGroup="NameRow" />
<RowDefinition Height="auto" SharedSizeGroup="AgeRow" />
<RowDefinition Height="auto" SharedSizeGroup="GenderRow" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" VerticalAlignment="Center" Padding="3,0,3,0" Text="{Binding Path=Name}" />
<TextBlock Grid.Row="1" VerticalAlignment="Center" Padding="3,0,3,0" Text="{Binding Path=Age}" />
<TextBlock Grid.Row="2" VerticalAlignment="Center" Padding="3,0,3,0" Text="{Binding Path=Gender}" />
</Grid>
</Border>
</DataTemplate>
<ControlTemplate x:Key="MyListBoxTemplate">
<Grid Grid.IsSharedSizeScope="True">
<DockPanel>
<Border BorderThickness="1">
<Grid DockPanel.Dock="Left">
<Grid.RowDefinitions>
<RowDefinition Height="auto" SharedSizeGroup="NameRow" />
<RowDefinition Height="auto" SharedSizeGroup="AgeRow" />
<RowDefinition Height="auto" SharedSizeGroup="GenderRow" />
</Grid.RowDefinitions>
<Button Template="{StaticResource HeaderButtonTemplate}" Grid.Row="0">Name</Button>
<Button Template="{StaticResource HeaderButtonTemplate}" Grid.Row="1" Content="Age" />
<Button Template="{StaticResource HeaderButtonTemplate}" Grid.Row="2" Content="Gender"/>
</Grid>
</Border>
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal" />
</DockPanel>
</Grid>
</ControlTemplate>
</Window.Resources>
<Grid>
<StackPanel Margin="10,10,10,10">
<TextBlock Text="This is an example of a pivoted grid" Margin="0,10, 0, 10" />
<ListBox x:Name="MyListBox" Height="auto"
ItemTemplate="{StaticResource MyDataTemplate}"
Template="{StaticResource MyListBoxTemplate}"
ItemsSource="{Binding Source={StaticResource PersonsProvider}}"
VerticalAlignment="Top" />
</StackPanel>
</Grid>
</Window>