我有一个列表框,我在其中使用 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>...
我试图让 wrappanel 具有这样一种行为,即当宽度变宽时,项目向右填充,并在窗口变窄时根据需要进行包裹。我玩过它,但正确的组合让我望而却步。有人有建议吗?
我的下一个目标是能够重新排序/排序项目并更新渲染。
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
它应该像你描述的那样工作My next goal would be able to reorder/ sort the items and have the render update.
你不必为此做任何特别的事情,这是
ListBox
的正常行为。 .只需更改排序顺序(使用 ICollectionView.SortDescriptions
),UI 将反射(reflect)更改
关于WPF 列表框包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4139580/