我创建了一个水平方向的列表框。当我加载内容时,在stackpanel中stackpanel的大小会自动调整到里面存储的内容的大小。如何在列表框中实现这一点?
这是我在 XAML 中的列表框代码:
<ListBox Name="WebScrollView"
Grid.Row="2"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectionMode="Multiple"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Height" Value="Auto" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top"
HorizontalAlignment="Center"
/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>