How do I make WPF ListView items repeat horizontally, like a horizontal scrollbar?

WpfXamlListviewAlignment

Wpf Problem Overview


I have a WPF ListView which repeats the data vertically. I cannot figure out how to make it repeat horizontally, like the slideshow view in Windows Explorer. My current ListView definition is:

<ListView ItemsSource="{StaticResource MyDataList}" ItemTemplate="{StaticResource ListViewTemplate}">
</ListView>

The DataTemplate is (although I believe this should not matter);

                <Rectangle HorizontalAlignment="Stretch" Margin="0,1,0,0" x:Name="rectReflection" Width="Auto" Grid.Row="1" Height="30">
                    <Rectangle.Fill>
                        <VisualBrush Stretch="None" AlignmentX="Center" AlignmentY="Top" Visual="{Binding ElementName=imgPhoto}">
                            <VisualBrush.RelativeTransform>
                                <TransformGroup>
                                    <MatrixTransform Matrix="1,0,0,-1,0,0" />
                                    <TranslateTransform Y="1" />
                                </TransformGroup>
                            </VisualBrush.RelativeTransform>
                        </VisualBrush>
                    </Rectangle.Fill>
                    <Rectangle.OpacityMask>
                        <RadialGradientBrush GradientOrigin="0.5,1.041">
                            <RadialGradientBrush.RelativeTransform>
                                <TransformGroup>
                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.202" ScaleY="2.865"/>
                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                    <TranslateTransform X="-0.002" Y="-0.491"/>
                                </TransformGroup>
                            </RadialGradientBrush.RelativeTransform>
                            <GradientStop Color="#D9000000" Offset="0"/>
                            <GradientStop Color="#01FFFFFF" Offset="0.8"/>
                        </RadialGradientBrush>
                    </Rectangle.OpacityMask>
                </Rectangle>
            </Grid>
        </Border>
    </DataTemplate>

Wpf Solutions


Solution 1 - Wpf

Set the ItemsPanel of the ListView to a horizontal StackPanel. Like this:

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"></StackPanel>
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

Solution 2 - Wpf

Perhaps a better way to do this would be to use a VirtualizingStackPanel which has all of the same properties but is much more performant especially for listboxes with lots of items.

Solution 3 - Wpf

I found it easier to go this way

<ItemsControl ItemsSource="{Binding Path=Steps}">
<ItemsControl.ItemTemplate>
	<DataTemplate>
		<TextBlock Text="{Binding PageName}" Padding="10" />
	</DataTemplate>
</ItemsControl.ItemTemplate>	
<ItemsControl.ItemsPanel>
	<ItemsPanelTemplate>
		<WrapPanel></WrapPanel>
	</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRyan O&#39;NeillView Question on Stackoverflow
Solution 1 - WpfBoyanView Answer on Stackoverflow
Solution 2 - WpfNate NoonenView Answer on Stackoverflow
Solution 3 - Wpfst35lyView Answer on Stackoverflow