【问题标题】:WPF horizonal ListView with multiple rows具有多行的 WPF 水平 ListView
【发布时间】:2020-08-27 06:43:12
【问题描述】:

我正在尝试实现一个水平可滚动的 GridView,类似于 UWP 所拥有的,但在 WPF 中使用 ListView。这就是我要显示的内容:

A C E G I ...
B D F H J ...

    <ListView Name="MainGrid"
              Grid.Row="1"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              ItemsSource="{Binding Source}"
              ItemTemplateSelector="{StaticResource TemplateSelector}"\>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    </ListView>

这可能吗?

【问题讨论】:

  • 你试过 ListView.ScrollViewer.VerticalScrollBarVisibility="Disabled"
  • 但我不关心滚动条。我需要水平显示项目并实际左右滚动。
  • 如果您设置 VerticalScrollBarVisibility="Disabled" 和 WrapPanel Orientation="Vertical" 您可以水平显示项目并左右滚动。试试....
  • 您是否考虑过使用 XAML 岛使用本机 UWP 控件?

标签: c# wpf xaml listview gridview


【解决方案1】:

这就是我想的你想要的..

    <ListView ScrollViewer.VerticalScrollBarVisibility="Disabled">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel  Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <Button Content="A"
                Width="100"
                Height="100" />
        <Button Content="B"
                Width="100"
                Height="100" />
        <Button Content="C"
                Width="100"
                Height="100" />
        <Button Content="D"
                Width="100"
                Height="100" />
        <Button Content="E"
                Width="100"
                Height="100" />
        <Button Content="F"
                Width="100"
                Height="100" />
        <Button Content="G"
                Width="100"
                Height="100" />
        <Button Content="H"
                Width="100"
                Height="100" />
        <Button Content="I"
                Width="100"
                Height="100" />
        <Button Content="J"
                Width="100"
                Height="100" />
    </ListView>

【讨论】:

  • 我试过了,底部单元格部分可见,我将添加到 ListView 中的任何高度。当它们离开屏幕时,它们也不能水平滚动。
【解决方案2】:
<ListView Name="MainGrid"
          Grid.Row="1"
          HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
          ItemsSource="{Binding Source}"
          ItemTemplateSelector="{StaticResource TemplateSelector}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
             <WrapPanel ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

可能

【讨论】:

  • 它可以水平滚动,但会显示单行项目。我需要 2 行,就像我的例子一样。
猜你喜欢
  • 2018-10-01
  • 2010-11-05
  • 2016-02-19
  • 2015-02-11
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
相关资源
最近更新 更多