简体   繁体   English

Xaml-StackPanel中的垂直滚动条

[英]Xaml - Vertical scrollbar in stackpanel

I have creating a wpf application and in my settings panel I have tons of UI elements. 我创建了一个wpf应用程序,并且在我的设置面板中有大量的UI元素。 The problem is that when I resize the window some of these elements are not visible anymore. 问题是,当我调整窗口大小时,其中某些元素不再可见。 Is there any way to add a simple vertical scrollbar? 有什么方法可以添加简单的垂直滚动条?

I have tried this below and add my content into it : 我已经在下面尝试过并将其内容添加到其中:

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

I'm not sure if I put the ScrollViewer to the right Place but I got this error : 我不确定是否将ScrollViewer放置在正确的位置,但是出现此错误:

The member resources is not recognized or is not accessible 会员资源未被识别或无法访问

and for this error I have tried to replace the Page.Resources with Window.Resources but it did not help. 对于此错误,我尝试用Window.Resources替换Page.Resources ,但没有帮助。

Anyways how could I get my vertical scrollbar working? 无论如何,如何使垂直滚动条正常工作? Any helps? 有帮助吗?

Problem solved by removing the Width and Height properties from the Page. 通过从页面删除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>

You should get rid of the StackPanel . 您应该摆脱StackPanel A StackPanel measures its children with an infinite space and therefore it doesn't work very well with scroll bars: StackPanel用无限的空间测量其子级,因此它与滚动条不能很好地配合使用:

Horizontal scroll for stackpanel doesn't work StackPanel的水平滚动不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM