wpfstackpanelfile-browserhorizontallist

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?


Solution

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

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