Windows 8 ListView with horizontal item flow

You can use a ListView this way:

<ListView
    Height="500"
    VerticalAlignment="Center"
    ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.VerticalScrollBarVisibility="Disabled"
    ScrollViewer.HorizontalScrollMode="Enabled"
    ScrollViewer.VerticalScrollMode="Disabled"
    ScrollViewer.ZoomMode="Disabled"
    SelectionMode="None">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsStackPanel
                Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>

— that gives it a horizontal panel and the right ScrollBars for horizontal scrolling.

Both ListView and GridView can cause problems when you get larger items. I think by default the items might be sized based on the size of the first item added. You can set that size manually though:

<ListView.ItemContainerStyle>
    <Style
        TargetType="ListViewItem"><!-- note - for GridView you should specify GridViewItem, for ListBox - ListBoxItem, etc. -->
        <Setter
            Property="Height"
            Value="200" /> <!-- this is where you can specify the size of your ListView items -->
        <Setter
            Property="Width"
            Value="350" />
    </Style>
</ListView.ItemContainerStyle>

— note that all items need to be the same size.

— also note – I have changed this answer to replace a StackPanel with an ItemsStackPanel which is virtualized, so it should get you better performance and lower memory usage for large data sets, but PLEASE – don’t create layouts with large, horizontally scrollable lists. They might be a good solution in some very limited scenarios, but in most cases they will break many good UI patterns and make your app harder to use.

Leave a Comment