1

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?

A. Wolf
  • 1,309
  • 17
  • 39
  • 1
    If listview is not compulsory then you should go with wrap panel. – maulik kansara Apr 21 '18 at 09:56
  • Put a wrap panel as the itemspanel of a listbox or itemscontrol. Like this does: https://social.technet.microsoft.com/wiki/contents/articles/33327.wpf-wrappanel-itemspanel-last-of-line.aspx – Andy Apr 21 '18 at 10:16

2 Answers2

3

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

<ListView ItemsSource="{Binding xxx}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>
Evaniar
  • 133
  • 1
  • 11
0

Use a WrapPanel and specify the width.

<ListView ItemsSource="your-source">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel width="1200" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>
Matteo
  • 57
  • 1
  • 9