WPF 列表框包装

标签 wpf xaml listbox wrappanel

我有一个列表框,我在其中使用 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?



您拥有的代码几乎正确,只需更改 OrientationHorizontal它应该像你描述的那样工作

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/

相关文章:

c# - 如何通过 WPF 中的 DataGrid SelectedItems Linq?

wpf - 在 Xaml 中将 TreeView 与 ContextMenu 绑定(bind)

c# - 为什么我的应用程序找不到默认的附属程序集 en-US 资源?

c# - 如何同步ListBox的SelectedItem?

c# - 将列表框绑定(bind)到 WPF 中字符串类型的 Observable 集合

c# - 从 ListBox 中的数据对象获取 DataTemplate

c# - 将默认资源样式应用于所有 DataGridTextColumns

WPF:MenuItem 内的按钮,关闭菜单

c# - WPF:ListView 中列表属性的总和

c# - 在 ListView 的 gridview 中使用空格/输入选中/取消选中复选框 - wpf