开发者

Vertical Scroll in stackpanel

开发者 https://www.devze.com 2023-01-14 23:23 出处:网络
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 m

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.


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消