在Silverlight中使用WrapPanel实现ListBox布局

3

我有一个 Silverlight 应用程序,其中有一个特定宽度的 ListBox。我正在代码后台动态添加项目到这个 ListBox 中。如果这些项目需要比分配的空间更多的空间,我希望这些项目会换行到下一行,并且 ListBox 的高度会增加。目前运行时,我的 ListBox 中会出现水平滚动条。此外,没有换行,因此也没有增长。我做错了什么?以下是我的 ListBox:

<ListBox x:Name="myListBox" Grid.Column="1" Width="600" MinHeight="24">
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <controlsToolkit:WrapPanel />
    </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
</ListBox>

感谢您的帮助!

1个回答

11
尝试将 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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接