Xaml - 堆栈面板中的垂直滚动条

Xaml - Vertical scrollbar in stackpanel

我创建了一个 wpf 应用程序,在我的设置面板中有大量 UI 元素。问题是当我调整 window 大小时,其中一些元素不再可见。有没有办法添加一个简单的垂直滚动条?

我已经在下面尝试过并将我的内容添加到其中:

    <ScrollViewer VerticalScrollBarVisibility="Auto">
       <Grid>
          <StackPanel>
              //Content
          </StackPanel>
       </Grid>
    </ScrollViewer>

我不确定我是否将 ScrollViewer 放在了正确的位置,但我收到了这个错误:

The member resources is not recognized or is not accessible

对于这个错误,我尝试用 Window.Resources 替换 Page.Resources 但没有帮助。

无论如何,我怎样才能让我的垂直滚动条工作?有帮助吗?

通过从页面中删除 WidthHeight 属性解决了问题。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Height="800" Width="1400"
      WindowTitle="ScrollViewer Sample">
  <ScrollViewer VerticalScrollBarVisibility="Auto">
     <Grid>
       <StackPanel>
          //Content
       </StackPanel>
     </Grid>
  </ScrollViewer>
</Page>

你应该去掉 StackPanelStackPanel 用无限 space 测量它的 children,因此它不能很好地与滚动条一起工作: