Dhinnesh Jeevan
Dhinnesh Jeevan

Reputation: 549

Need advice on customizing ListBox template

I have a ListBox of CheckBox values, the number of values vary from time to time, it can be 10, 15, 100, etc..

I would like to customize the way the values are displayed. Currently, if I have 50 values, they are all displayed vertically, just one column.

I would like to have it such that, 1 column will have a maximum of 10 values, and I am able to scroll horizontally to view the values at other columns.

I tried using ItemsPanelTemplate with StackPanel orientation horizontal, but well, all values are now in 1 row.

Please advice.

Thanks!

Upvotes: 0

Views: 45

Answers (1)

Steven Rands
Steven Rands

Reputation: 5421

You could try changing the panel used by your ListBox to a WrapPanel instead. Set its Orientation to Vertical, then size the height of the ListBox so it fits 10 items in each "column" before starting a new column.

<ListBox Height="..."
    ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.VerticalScrollBarVisibility="Disabled">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

If you want 10 items in each column but don't want to explicitly set the height of the ListBox then the only solution I can think of is writing a custom Panel.

Upvotes: 1

Related Questions