我使用的是 Silverlight 4。我有一个 UserControl
,其 LayoutRoot
包装在 ScrollViewer
中。我希望滚动条仅在 LayoutRoot
溢出页面时才出现。可以自动执行此操作,还是应该编写代码来检测内容是否会溢出并相应地设置滚动条可见性?
最佳答案
您应该能够使用 ScrollViewer.HorizontalScrollBarVisibility
自动执行此操作和 ScrollViewer.VerticalScrollBarVisibility
特性。以下是这些属性的所有可能值的列表(ScrollBarVisibility
枚举):
- 已禁用
- 自动
- 隐藏
- 可见
我认为“自动”就是您正在寻找的:
Auto: A ScrollBar appears and the dimension of the ScrollViewer is applied to the content when the viewport cannot display all of the content. For a horizontal ScrollBar, the width of the content is set to the ViewportWidth of the ScrollViewer. For a vertical ScrollBar, the height of the content is set to the ViewportHeight of the ScrollViewer.
希望这有帮助!
关于Silverlight:滚动查看器仅在内容溢出时出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4413888/