joshwl2003
joshwl2003

Reputation: 463

Vertical Scroll in stackpanel

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>
              </StackPanel>
          </ScrollViewer>
      </Grid>
</GroupBox>

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

Upvotes: 13

Views: 35570

Answers (2)

John Bowen
John Bowen

Reputation: 24453

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.

Upvotes: 4

ASanch
ASanch

Reputation: 10373

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>

Upvotes: 23

Related Questions