在Silverlight中的ListBox中使用WrapPanel

use*_*886 3 silverlight listbox wrappanel

我有一个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>
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

Dan*_*air 11

尝试在ListBox上将ScrollViewer.Horizo​​ntalScrollBarVisibility设置为Disabled以防止水平滚动并强制进行包装.

<ListBox x:Name="myListBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="1" Width="600" MinHeight="24">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <controlsToolkit:WrapPanel />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)