更改项目的显示WPF列表框中 [英] Change how items are displayed WPF list box

查看:109
本文介绍了更改项目的显示WPF列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示的ListBox WPF窗口。我已经改变了的ListBox 的项目模板,以便在列表框中显示可以选择矩形的项目。

I have a WPF window which displays a ListBox. I've changed the ListBox's item template so that the list box displays rectangular items which can be selected.

现在我想修改 ListBox的 ItemsPanelTemplate ,这样的项目都显示在一个网格,而不是任一垂直或水平列表。具体来说,我想第一个项目在的ListBox ,然后第二个项目在它下面和第三的右上角去下直到下一个项目的高度将使项目比的ListBox 本身的高度更高的列。在这一点上,应该直接启动的第二列的第一个项目的右侧添加。如果所有组合列的总宽度比的ListBox 然后水平滚动条应该出现的宽度。

Now I'd like to modify the ListBox's ItemsPanelTemplate so that the items are displayed in a grid instead of either a vertical or horizontal list. Specifically I'd like the first item to go in the top right corner of the ListBox and then second item below it and third under that until the height of the next item would make the column of items taller than the height of the ListBox itself. At that point it should start a second column directly to the right of the first item added. If the total width of all of the columns combined was greater than width of the ListBox then a horizontal scroll bar should appear.

有没有办法只是通过修改来获得这种效果的 ItemsPanelTemplate 或者我需要延长的ListBox 类本身?在任何情况下,我将如何得到呢?

Is there a way to get that effect just by modifying the ItemsPanelTemplate or do I need to extend the ListBox class itself? In either case, how would I got about it?

感谢您的帮助!

推荐答案

我没有测试过这一点,但我怀疑你可以通过交换使用的的ListBox 到<$ C,其默认面板所需的效果$ C> WrapPanel :

I haven't tested this, but I suspect you can get the desired effect by swapping out the default panel used by the ListBox to a WrapPanel:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Vertical"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

这篇关于更改项目的显示WPF列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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