views:

138

answers:

1

Hello

When I set a column's width or a row's height to star, and I fill in content that is bigger than the available rectangle, the row keeps on growing 'underground':

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="100" Width="100">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel>
            <Button Content="Button" />
            <Button Content="Button" />
            <Button Content="Button" />
        </StackPanel>
        <StackPanel Grid.Row="1" 
                ScrollViewer.CanContentScroll="True" 
                ScrollViewer.VerticalScrollBarVisibility="Auto" 
                ScrollViewer.IsDeferredScrollingEnabled="True">
            <Button Content="Button" />
            <Button Content="Button" />
            <Button Content="Button" />
        </StackPanel>
    </Grid>
</Window>

I want that StackPanel should not grow underground, instead it should show scrollbars.

Note, I need all the size dynamic so everything changes according to the user resizing the parents.
I have the same issue with columns.
PS. RowDefinition.Height is always * by default.

UPDATE

I guess the problem is the grid and the previous snippet I posted didn't provide the whole story, please review:

<Window x:Class="Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"            
Title="Window1" Height="200">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="1">
            <StackPanel>
                <TextBlock Text="Hello"/>
                <TextBox Text="World!"/>
            </StackPanel>
            <ScrollViewer>
                <StackPanel>
                    <Button Content="Button"/>
                    <Button Content="Button"/>
                    <Button Content="Button"/>
                    <Button Content="Button"/>
                    <Button Content="Button"/>
                </StackPanel>
            </ScrollViewer>
        </StackPanel>
    </Grid>
</Window>
+2  A: 

I'm not sure that StackPanel has a built in ScrollViewer so setting the ScrollViewer.* attached proeprties really has no effect on it.

Have you tried wrapping the StackPanel with a ScrollViewer explicitly? For example:

<ScrollViewer Grid.Row="1"
       ScrollViewer.CanContentScroll="True" 
       ScrollViewer.VerticalScrollBarVisibility="Auto" 
       ScrollViewer.IsDeferredScrollingEnabled="True">
    <StackPanel>
        <Button Content="Button" />
        <Button Content="Button" />
        <Button Content="Button" />
    </StackPanel>
</ScrollViewer>
Aviad P.
Bingo. Fifteen.
JMD
I am so sorry, the problem was indeed the ScrollViewer, but I guess I didn't reach the solution yet.
Shimmy
Put your `ScrollViewer` in the grid row, don't nest it within the `StackPanel`.
Aviad P.
The problem is the grid. Becuase a ListBox surely has a built-in ScrollViewer and sometimes I want to have the ListBox nested in a StackPanel. The problem is that the StackPanel keeps on growing underground, or better said, whatever is under the RowHeight*, grows underground.
Shimmy
The problem is that the ScrollViewer is not limited in height when placed inside a StackPanel, that's why you'll never get a vertical scroll bar on it. You need to put your ScrollViewer directly in the grid row so that its height is constrained, that way when its content grow beyond its allotted height, you'll get scrollbars.
Aviad P.