具有项目水平排列的 WPF ListView? [英] WPF ListView with horizontal arrangement of items?

查看:32
本文介绍了具有项目水平排列的 WPF ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以类似于列表模式下的 WinForms ListView 的方式在 ListView 中布置项目.也就是说,项目在 ListView 中不仅垂直而且水平布置.

I want to lay out items in a ListView in a similar manner to the WinForms ListView in List mode. That is, where items are laid out not just vertically but horizontally in the ListView as well.

我不介意这些物品是否是这样布置的:

I don't mind if the items are laid out like this:

1 4 7
2 5 8
3 6 9

1 4 7
2 5 8
3 6 9

或者像这样:

1 2 3
4 5 6
7 8 9

1 2 3
4 5 6
7 8 9

只要它们垂直和水平呈现,以最大限度地利用可用空间.

As long as they are presented both vertically and horizontally in order to maximize the use of available space.

我能找到的最接近的是这个问题:

The closest I could find was this question:

我该怎么做使 WPF ListView 项目水平重复,就像水平滚动条一样?

仅水平排列项目.

推荐答案

听起来您正在寻找的是 WrapPannel,它将水平放置项目直到没有更多空间,然后移动到下一行,如下所示:

It sounds like what you are looking for is a WrapPannel, which will lay the items out horizontally until there is no more room, and then move to the next line, like this:

(MSDN)
替代文字 http://i.msdn.microsoft.com/Cc295081.b1c415fb-9a32-4a18-aa0b-308fca994ac9(en-us,Expression.10).png

您也可以使用 UniformGrid,它将项目按一定数量的行或列排列.

You also could use a UniformGrid, which will lay the items out in a set number of rows or columns.

我们使用 ListView、ListBox 或任何形式的 ItemsControl 中的这些其他面板来排列项目的方式是通过更改 ItemsPanel 属性.通过设置 ItemsPanel,您可以从 ItemsControls 使用的默认 StackPanel 更改它.使用 WrapPanel,我们还应该将宽度设置为 此处所示.

The way we get the items to arange using these other panels in a ListView, ListBox, or any form of ItemsControl is by changing the ItemsPanel property. By setting the ItemsPanel you can change it from the default StackPanel that is used by ItemsControls. With the WrapPanel we also should set the widths as shown here.

<ListView>
   <ListView.ItemsPanel>
      <ItemsPanelTemplate>
         <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), 
            RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
            ItemWidth="{Binding (ListView.View).ItemWidth, 
            RelativeSource={RelativeSource AncestorType=ListView}}"
            MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
            ItemHeight="{Binding (ListView.View).ItemHeight, 
            RelativeSource={RelativeSource AncestorType=ListView}}" />
      </ItemsPanelTemplate>
   </ListView.ItemsPanel>
...
</ListView>

这篇关于具有项目水平排列的 WPF ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆