我有以下网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Height="50" Background="Gainsboro" Grid.Row="0"/>
<Border Background="AliceBlue" Grid.Row="1">
<ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="asdasdfasdf3dfasdf"/>
</Border>
<Border Height="60" Background="Aquamarine" Grid.Row="3"/>
</Grid>
为什么ListBox的scrollviewer没有启用?最后一个边框被推出窗口。如果我将 Grid.Row 2 Height 设置为 * star - 它工作得很好。是否可以在自动高度网格行中使用带有滚动查看器的列表框?
最佳答案
Auto
使您的控件根据需要调整大小。因此你的ListBox
将调整自身大小以显示其所有内容,并且永远不会显示滚动条。
*
使您的控件采用可用大小,并且不会超出该大小。
您需要做的是定义 MaxHeight
ListBox
的属性或使用 *
作为 RowDefinition
中的高度.
关于wpf - 具有自动高度的网格行中的列表框。滚动条不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10751357/