A. Wolf
A. Wolf

Reputation: 1347

Horizontal ListView on multiple lines (WPF)

I want to implement an horizontal ListView which can have multiple lines, like the file explorer:

enter image description here
I found that I have to use StackPanelfor the ItemPanelTemplate here, but I prefer to have multiple lines instead of the horizontal scrollbar. I think that the idea is when the StackPanel width reaches the ListView width, go the next line/create a new StackPanel. I don't know if it's correct, but maybe it can help to understand what am I looking for.

How can I implement this?

Upvotes: 2

Views: 1793

Answers (3)

Elyas Nategh
Elyas Nategh

Reputation: 550

<ListBox ItemsSource="{Binding Files}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

Upvotes: 0

Matteo
Matteo

Reputation: 109

Use a WrapPanel and specify the width.

<ListView ItemsSource="your-source">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel width="1200" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

Upvotes: 1

Evaniar
Evaniar

Reputation: 143

You need to use a WrapPanel instead of a StackPanel as ItemsPanelTemplate.

<ListView ItemsSource="{Binding xxx}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

Upvotes: 4

Related Questions