WPF ListBox滚动条不起作用

时间:2013-03-08 12:34:58

标签: 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>

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

由于

1 个答案:

答案 0 :(得分:10)

您需要将ListBox放在网格中。 StackPanel有一个 无限高度,因此ScrollBar不会启用或显示。

<Grid>
  <ListBox VerticalAlignment="Stretch" />
</Grid>
相关问题