简体   繁体   English

如何使WPF ListView项目水平重复,如水平滚动条?

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

I have a WPF ListView which repeats the data vertically. 我有一个WPF ListView,它垂直重复数据。 I cannot figure out how to make it repeat horizontally, like the slideshow view in Windows Explorer. 我无法弄清楚如何使其重复水平,如Windows资源管理器中的幻灯片视图。 My current ListView definition is: 我当前的ListView定义是:

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

The DataTemplate is (although I believe this should not matter); DataTemplate是(尽管我认为这无关紧要);

                <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>

Set the ItemsPanel of the ListView to a horizontal StackPanel. 将ListView的ItemsPanel设置为水平StackPanel。 Like this: 像这样:

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

也许更好的方法是使用VirtualizingStackPanel,它具有所有相同的属性,但性能更高,特别是对于包含大量项目的列表框。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM