【问题标题】:ListBox in Grid Row with Auto height. Scrollbar is not working具有自动高度的网格行中的列表框。滚动条不起作用
【发布时间】:2012-05-25 08:53:46
【问题描述】:

我有以下网格:

<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 的滚动查看器?最后一个边框被推出窗口。如果我将 Grid.Row 2 Height 设置为 * 星 - 它工作得很好。是否可以在自动高度网格行中使用带有滚动查看器的列表框?

【问题讨论】:

    标签: wpf scroll listbox grid


    【解决方案1】:

    Auto 使您的控件根据需要调整大小。因此,您的 ListBox 将自行调整大小以显示其所有内容,并且永远不会显示滚动条。

    * 使您的控件采用可用大小,并且不会超出该大小。

    您需要为ListBox 定义MaxHeight 属性或使用* 作为RowDefinition 中的高度。

    【讨论】:

    • 我怕你证实我的假设。星号不好,因为它使列表框的边框比必要的大。 MaxHeight 可以正常工作,但要使其填充所有可用空间,我必须在每次调整窗口大小时在代码中进行计算。我想避免这种情况,但这似乎是不可避免的;)
    猜你喜欢
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多