tags:

views:

19

answers:

1

I have managed to reproduce a weird behavior in the auto scrollviewer functionality of a listbox when it is placed in a 2*2 grid.

If you try to use the following xaml as it is you will see that the vertical scrollviewer is there but not visible (it just exceeds the width of the first column)

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="200" Width="200">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>

    <ListBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" >
        <ListBox.Items>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
            <TextBlock Text="Item"/>
        </ListBox.Items>
    </ListBox>

    <Canvas Background="Yellow" Grid.Row="0" Grid.Column="1" MinHeight="20"/>
    <Canvas Background="Red" Grid.Row="1" Grid.Column="1" MinHeight="20"/>

</Grid>

The problematic control as far as i can tell is the first canvas (the yellow one). To be more specific WPF does not like any controls to be placed in row=0 column=1, and breaks the scrollviewer functionality.

Is this issue reproducible to anyone else or just me?

A: 

Yes, it is reproducible, actually, it is reproducible in every grid, location or size. When you add an actual Height to the ListBox, the scrollbar returns.

However, the real problem seems to come from the yellow canvas, which is overlapping the listbox. Whether that's a bug or not, I don't know. Remove the yellow canvas, and you're fine. Change the row from 0 to 1 and you're also fine. But, when you give the ListBox a specific height, as mentioned above, the scrollbar comes back, too:

<ListBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Height="100">
    <ListBox.Items>
        <TextBlock Text="Item 1"/>
        <TextBlock Text="Item 2"/>
        <TextBlock Text="Item 3"/>
        <TextBlock Text="Item 4"/>
        <TextBlock Text="Item 5"/>
        <TextBlock Text="Item 6"/>
        <TextBlock Text="Item 7"/>
        <TextBlock Text="Item 8"/>
        <TextBlock Text="Item 9"/>
        <TextBlock Text="Item 10"/>
        <TextBlock Text="Item 11"/>
        <TextBlock Text="Item 12"/>
    </ListBox.Items>
</ListBox>
Abel