wpf 堆栈面板中的垂直滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3621140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:05:18  来源:igfitidea点击:

Vertical Scroll in stackpanel

wpf

提问by joshwl2003

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?

我正在尝试将滚动条放置在堆栈面板上。滚动条显示但根本不允许用户移动滚动条。我的 XMAL 有什么问题吗?或者还有什么问题?

<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.

堆栈面板的内容是扩展器,其中包含数据。

回答by ASanch

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 的 Width 和 Height 以使内部 ScrollViewer 工作。试试这个,你会发现它会正常工作。

<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>

回答by John Bowen

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.

ScrollViewer 的默认设置HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible"是您所看到的 ScrollViewer 的可见但禁用状态。如果 ScrollViewer 的内容变得比可用空间高,则垂直条将变为交互式并允许滚动。尝试设置VerticalScrollBarVisibility="Auto"以更清楚地查看它何时处于活动状态。