1 <Window Background="cornsilk"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 x:Class="ListBox_Index.Window1"
8 <Grid.ColumnDefinitions>
11 </Grid.ColumnDefinitions>
20 </Grid.RowDefinitions>
23 <Style TargetType="Separator">
24 <Setter Property="Template">
26 <ControlTemplate TargetType="{x:Type Separator}">
27 <Border Width="2" Height="12" Margin="4" Background="Gray"/>
33 <Style TargetType="ListBox">
34 <Setter Property="ItemsPanel">
37 <StackPanel Orientation="Horizontal"
38 VerticalAlignment="Center"
39 HorizontalAlignment="Center"/>
47 <TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="0" FontSize="24">Horizontal ListBox</TextBlock>
48 <TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="1" FontSize="14" Grid.ColumnSpan="2">The following application demonstrates how to create a horizontal list box.</TextBlock>
51 Margin="10, 10, 3, 3" Height="50"
52 Grid.Column="0" Grid.Row="2"
54 SelectionChanged="PrintText">
55 <ListBoxItem>Item 1</ListBoxItem>
57 <ListBoxItem>Item 2</ListBoxItem>
59 <ListBoxItem>Item 3</ListBoxItem>
61 <ListBoxItem>Item 4</ListBoxItem>
63 <ListBoxItem>Item 5</ListBoxItem>
65 <ListBoxItem>Item 6</ListBoxItem>
67 <ListBoxItem>Item 7</ListBoxItem>
69 <ListBoxItem>Item 8</ListBoxItem>
71 <ListBoxItem>Item 9</ListBoxItem>
73 <ListBoxItem>Item 10</ListBoxItem>
75 <TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="2" Grid.RowSpan="2" FontSize="12" TextWrapping="WrapWithOverflow" VerticalAlignment="Center">The list box uses a style to make it horizontal. The list box items are separated by styled separators.</TextBlock>
77 <Label Margin="10, 10, 3, 3" Name="label1" Grid.Column="0" Grid.Row="5"/>
78 <TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="5" FontSize="12" TextWrapping="WrapWithOverflow" VerticalAlignment= "Center">Click one of the list box items.</TextBlock>