如何在 C# 中向窗口添加滚动条
我创建了一个窗口,如下所示:
Window myWindow = new Window();
如何向此窗口添加垂直滚动条,并使滚动条仅在高度不够大以显示所有元素时才可见。
I have created a window as follows:
Window myWindow = new Window();
How can I add a Vertical Scroll Bar to this Windows and make the Scroll Bar only visible if the Height isn't large enough to show all the elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 ScrollViewer 元素添加到窗口中,并将必要的控件放入 ScrollViewer 中控制。
或者,如果您想在代码隐藏文件中对其进行编码,您可以编写
You could add a ScrollViewer element to your window and put the necessary controls into the ScrollViewer control.
Or if you want to code it in the code-behind file you could write
您不能将滚动条添加到窗口本身。您只能向控件添加滚动条。 IE 到窗口内的网格。
示例:
编辑:
刚刚意识到 Window 也有一个 ScrollViewer 属性。我不确定这个属性如何适用于窗口以及这样的窗口会是什么样子。尝试了一下,但没有出现滚动条。
编辑2:
You cannot add a scrollbar to a window itself. You can only add scrollbars to controls. I.E. to a grid inside your window.
Example:
EDIT:
Just realized that Window also has a ScrollViewer property. I'm not sure how this property works for a Window and how such a window would look like. Gave it a try, but no scrollbars show up.
EDIT 2:
试试这个
try this