Random programming things I'd want to remember

Monday, January 20, 2014

System.Windows.Control.ListBox does not scroll

An interesting one today. My ListBox would not scroll, and after looking into all usual suspects it still would not work. Turns out that the offender was the Grid, containing the ListBox. Here is XAML:
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                ...
            </StackPanel>            
           
            <ListBox ItemsSource="{Binding}" Grid.Row="1">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Description}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

My ListBox has a bunch of items and it does not scroll, even though there is no StackPanel in the DataTemplate. But, if I change the RowDefinition on the second row to say
                <RowDefinition Height="*" />

Then it scrolls just fine.

No comments: