【问题标题】:Horizontal ListView on multiple lines (WPF)多行水平 ListView (WPF)
【发布时间】:2018-10-01 21:39:31
【问题描述】:

我想实现一个水平的ListView,它可以有多行,比如文件资源管理器:


我发现ItemPanelTemplate here 必须使用StackPanel,但我更喜欢多行而不是水平滚动条。 我认为这个想法是当 StackPanel 宽度达到 ListView 宽度时,转到下一行/创建一个新的 StackPanel。我不知道它是否正确,但也许它可以帮助理解我在寻找什么。

我该如何实现?

【问题讨论】:

标签: wpf stackpanel file-browser horizontallist


【解决方案1】:

您需要使用WrapPanel 而不是StackPanel 作为ItemsPanelTemplate

<ListView ItemsSource="{Binding xxx}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

【讨论】:

    【解决方案2】:

    使用WrapPanel 并指定width

    <ListView ItemsSource="your-source">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel width="1200" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    </ListView>
    

    【讨论】:

      猜你喜欢
      • 2020-08-27
      • 2015-02-11
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 2010-09-26
      • 2010-11-05
      • 1970-01-01
      • 2019-03-14
      相关资源
      最近更新 更多