WPF 列表框包装 [英] WPF Listbox Wrapping

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

问题描述

我有一个列表框,我在其中使用 ListBox.ItemsPanel - WrapPanel.

I have a listbox in which I use a ListBox.ItemsPanel - WrapPanel.

<ListBox ItemsSource="{Binding Path=Applets}" Margin="10,92,10,10" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>

                <WrapPanel Orientation="Vertical" IsItemsHost="True">

                </WrapPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>



        <ListBox.ItemTemplate>...

我试图让包裹面板具有这样的行为,即当宽度变宽时项目填充到右侧,并在窗口变窄时根据需要进行包裹.我玩过它,但正确的组合让我望而却步.有人有建议吗?

I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?

我的下一个目标是能够重新排序/排序项目并更新渲染.

My next goal would be able to reorder/ sort the items and have the render update.

TIA

推荐答案

我试图让包裹面板具有这样的行为,即当宽度变宽时项目填充到右侧,并在窗口变窄时根据需要进行包裹.我玩过它,但正确的组合让我望而却步.有人有什么建议吗?

I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?

您的代码几乎是正确的,只需将 Orientation 更改为 Horizo​​ntal,它应该可以按照您的描述工作

The code you have is almost correct, just change the Orientation to Horizontal and it should work as you describe

我的下一个目标是能够重新排序/排序项目并更新渲染.

My next goal would be able to reorder/ sort the items and have the render update.

你不必为此做任何特别的事情,这是 ListBox 的正常行为.只需更改排序顺序(使用 ICollectionView.SortDescriptions),UI 就会反映更改

You don't have to do anything special for that, it's the normal behavior of a ListBox. Just change the sort order (using ICollectionView.SortDescriptions), and the UI will reflect the changes

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

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