Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listbox items orientation to horizontal

How to make the listbox items orientation to horizontal in the default styling of a listbox. What i mean by default is the style which we get using blend.

like image 747
Malcolm Avatar asked Aug 25 '10 12:08

Malcolm


1 Answers

Use the ItemsPanel property to replace the panel with a horizontal StackPanel:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

If you want to do this in a Style, just add a Setter that sets the ItemsPanel property:

<Style TargetType="ListBox">
    <!-- Rest of the style -->
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>
like image 128
Quartermeister Avatar answered Nov 13 '22 13:11

Quartermeister