WPF 列表框滚动条不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15294112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:57:55 来源:igfitidea点击:
WPF ListBox scrollbar is not working
提问by Stacked
<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>
My ListBox contains so many elements and actually the scrollbar should work but it's not even visible. Am I doing something wrong?
我的 ListBox 包含这么多元素,实际上滚动条应该可以工作,但它甚至不可见。难道我做错了什么?
Thanks
谢谢
回答by Jehof
You need to put the ListBox in a Grid. The StackPanel has an
infinite height, so that the ScrollBar does not get enabled or visible.
您需要将 ListBox 放在 Grid 中。StackPanel 具有
无限高度,因此 ScrollBar 不会被启用或可见。
<Grid>
<ListBox VerticalAlignment="Stretch" />
</Grid>

