ListBox in Grid Row with Auto height. Scrollbar is not working

冷暖自知 提交于 2019-12-14 03:53:06

问题


I have the following grid:

<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>

Why ListBox's scrollviewer is not enabled? Last border is pushed out of a window. If i set the Grid.Row 2 Height to * star - it works nicely. Is it possible to have listbox with scrollviewer in auto height grid row?


回答1:


Auto makes your control resize as it needs. Therefore your ListBox will resize itself to show all its content and the scroll bar will never been shown.

* makes your control to take the available size, and it does not grow beyond that.

What you need to do is either define the MaxHeight property for the ListBox or use * as height in RowDefinition.



来源:https://stackoverflow.com/questions/10751357/listbox-in-grid-row-with-auto-height-scrollbar-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!