Joe
Joe

Reputation: 2591

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

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?

Upvotes: 3

Views: 3441

Answers (1)

JSJ
JSJ

Reputation: 5691

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.

Upvotes: 3

Related Questions