WPF ListBox滚动条不起作用

Sta*_*ked 2 wpf listbox scrollbar

<ListBox Name="myListBx" ItemsSource="{Binding Collection}" Margin="5,5"
    SelectedValuePath="ColId"
    SelectedValue="{Binding Path=ColId}"
    SelectionMode="Multiple"
    BorderThickness="0" Background="{x:Null}" BorderBrush="{x:Null}"
    ScrollViewer.VerticalScrollBarVisibility ="Auto">
    <ListBox.ItemTemplate>
        <DataTemplate>
            // blabla
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

我的ListBox包含很多元素,实际上滚动条应该可以工作,但它甚至都不可见.难道我做错了什么?

谢谢

Jeh*_*hof 10

您需要将ListBox放在网格中.StackPanel具有
无限高度,因此ScrollBar不会启用或可见.

<Grid>
  <ListBox VerticalAlignment="Stretch" />
</Grid>
Run Code Online (Sandbox Code Playgroud)