Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: ScrollViewer in grid

I have a grid:

<Grid.RowDefinitions>
        <RowDefinition Height="100"/>
        <RowDefinition Height="*"/>
</Grid.RowDefinitions>

The second row is with scrollviewer:

    <ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
            <ItemsControl ItemsSource="{Binding SelectedUserControls}"/>
    </ScrollViewer>

I want the second row to be with scroll if needed, But the scroll is never visible, event if the items controls are bigger than the screen.

How can i get the scroll to appear when needed?

like image 808
Shoki Avatar asked Mar 09 '11 15:03

Shoki


2 Answers

EDIT:

Try removing 'MinHeight=400' and I bet it works!!

You have a MinHeight on your ItemsControl of 400. So until you have enough items to take up all 400, you will not see your scrollbar. I'm guessing the container holding your grid (or the explicit height on your grid is less that 400), and you have enough items to be too big for that container, but not enough items to fill the MinHeight of your ItemsControl.

Original Answer: I just ran a test app with 30 items in it (enough to fill the MinHeight) and it seems to work fine:

<Window x:Class="TestApp11.MainWindow" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:l="clr-namespace:TestApp11"
  Title="Window1" Loaded="Window_Loaded" Height="600" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
            <ItemsControl>
                ...
                 <ListBoxItem Content="Item 30" />
                ...
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</Window>

Does your container holding your grid have an explicit Height?

like image 162
Scott Avatar answered Oct 14 '22 08:10

Scott


Change MinHeight to MaxHeight.

like image 25
RayLoveless Avatar answered Oct 14 '22 10:10

RayLoveless