tags:

views:

60

answers:

2

I am trying to get a scroll bar to be placed on a stack panel. The scroll bar displays but will not allow for the user to move the scroll bar at all. Is there something wrong with my XMAL or is there more to it?

<GroupBox HorizontalAlignment="Left" Margin="268,8,0,0" VerticalAlignment="Top" Width="505.881" Height="352.653" Header="Metrics">
        <Grid>
            <ScrollViewer>
                <StackPanel>

The content of the stack panel is expanders with data contained with in them.

Please help.

+2  A: 

You must not set the Width and Height of the GroupBox in order to make the inner ScrollViewer work. Try this out and you'll see that it will work fine.

<GroupBox Header="Metrics" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="268,8,0,0">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <Expander Header="Expander">
                    <StackPanel>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                        <Button>Test</Button>
                    </StackPanel>
                </Expander>

            </StackPanel>
        </ScrollViewer>
    </Grid>
</GroupBox>
karmicpuppet
Thanks, does this also mean that no widths or heights can be set on anything inside of the scroll view?
joshwl2003
It's okay to set the width's and heights of items within the ScrollViewer. So in my sample code above, this means that a Width or Height for the inner StackPanel can be set. If you have it like <StackPanel Width="200" Height="200", this means that scrolling will be enabled whenever the ScrollViewer's width and/or height becomes less than 200.
karmicpuppet
+1  A: 

The default settings for ScrollViewer are HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" so what you're seeing is the visible but disabled state of the ScrollViewer. If the content of the ScrollViewer becomes taller than the available space the vertical bar will become interactive and allow scrolling. Try setting VerticalScrollBarVisibility="Auto" to more clearly see when it's active or not.

John Bowen