user38349
user38349

Reputation: 3025

How do you add a scroll bar to an expander panel?

I have a stack panel inside of an expander panel that I programaticaly adds check boxes to. Currently the exanpander stops at the bottom of the form, but the stack panel keeps growing. I would like the stack panel to be bounded by the expander and scroll to display the check boxes. Do I need house the check boxes in a list box to get the scroll functionality?

<Grid>
    <Expander Header="Expander1"  Margin="0,0,0,2" Name="Expander1" VerticalAlignment="Top" Background="Coral">
        <StackPanel Name="StackScroll" Margin="0,0,0,2"  Background="Aqua"></StackPanel>
    </Expander>
</Grid>

");

Upvotes: 5

Views: 13580

Answers (2)

Guy Starbuck
Guy Starbuck

Reputation: 21873

You can nest the StackPanel in a ScrollViewer:

  <Grid>  
    <Expander Header="Expander1"  Margin="0,0,0,2" Name="Expander1" VerticalAlignment="Top" Background="Coral">
      <ScrollViewer VerticalScrollBarVisibility="Auto">
        <StackPanel Name="StackScroll" Margin="0,0,0,2"  Background="Aqua">
        </StackPanel>
      </ScrollViewer>
    </Expander>
  </Grid>

Upvotes: 11

Pete OHanlon
Pete OHanlon

Reputation: 9146

Set ScrollViewer.VerticalScrollBarVisibility="Auto" in your StackPanel declaration.

Upvotes: 3

Related Questions