The following example creates a ListBox that displays items horizontally. The example sets the ItemsPanel to an ItemsPanelTemplate that has a StackPanel whose Orientation property is set to Horizontal.
<Grid>
<Grid.Resources>
<Style x:Key="horizontalListBoxStyle" TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<src:Items x:Key="items"/>
</Grid.Resources>
<ListBox ItemsSource="{StaticResource items}"
Style="{StaticResource horizontalListBoxStyle}"/>
</Grid>
The following example shows the collection of strings that the ListBox is bound to.
Public Class Items
Inherits System.Collections.ObjectModel.ObservableCollection(Of String)
Public Sub New()
Add("Item 1")
Add("Item 2")
Add("Item 3")
Add("Item 4")
Add("Item 5")
End Sub
End Class
public class Items :
System.Collections.ObjectModel.ObservableCollection<string>
{
public Items()
{
Add("Item 1");
Add("Item 2");
Add("Item 3");
Add("Item 4");
Add("Item 5");
}
}
The previous example produces output that resembles the following illustration.
ListBox with items arranged horizontally