WPF列表框包装 [英] WPF Listbox Wrapping
问题描述
我有一个列表框,其中使用了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
更改为Horizontal
,它就可以按照您的描述工作
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
),用户界面就会反映出更改
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屋!