Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display items in two columns in a ListView

I'm looking to layout a ListView in a Windows 8.1 app so that its elements wrap to (at most) two columns that read in order like a newspaper and scroll vertically, e.g.,

1 4
2 5
3

The closest I've gotten is:

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

but since MaximumRowsAndColumns is interpreted per the Orientation, the result is

1 2
3 4
5

switching the Orientation to Vertical gives me

1 2 3
4 5

Am I going to need a custom panel to do this? Another tactic is perhaps a gridview within a scrollviewer, but that seems a little hacky to me.

like image 749
Jim O'Neil Avatar asked Dec 16 '14 22:12

Jim O'Neil


1 Answers

You should use ItemsWrapGrid :

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <ItemsWrapGrid />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

This will give you the result that you want :

1 4
2 5
3
like image 154
Abdallah Shakhatreh Avatar answered Nov 03 '22 11:11

Abdallah Shakhatreh