我有一个 Silverlight 应用程序,它有一个特定宽度的 ListBox。我在我的代码隐藏中动态地向这个 ListBox 添加项目。如果项目需要的空间超过分配的空间,我希望项目换行到下一行并且 ListBox 的高度增加。当它现在运行时,一个水平滚动条出现在我的 ListBox 中。此外,没有包装,因此不会发生增长。我究竟做错了什么?这是我的列表框:
<ListBox x:Name="myListBox" Grid.Column="1" Width="600" MinHeight="24">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
感谢您的帮助!
最佳答案
尝试在 ListBox 上将 ScrollViewer.HorizontalScrollBarVisibility 设置为 Disabled 以防止水平滚动并强制换行。
<ListBox x:Name="myListBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="1" Width="600" MinHeight="24">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
关于silverlight - 在 Silverlight 的 ListBox 中使用 WrapPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5185448/