Silverlight:滚动查看器仅在内容溢出时出现?

标签 silverlight xaml scrollviewer

我使用的是 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/

相关文章:

c# - 是否可以在多个项目之间共享 ResourceDictionary 文件?

C# wpf scrollviewer 不像windows store app那样工作

.net - 需要创建一个具有标题和滚动条支持的上下文菜单

c# - 如何检查依赖对象是否包含依赖属性?

silverlight - 如何在 MVVM 应用程序中实现撤消/重做?

c# - 在 fluentribbon 按钮中设置 xaml 图标

c# - 创建 Silverlight 覆盖用户控件

c# - Silverlight 和 RIA 服务与 LINQ-to-SQL DataContext - 无法使用客户端 linq 查询

c# - Windows Phone 8.1 (Silverlight) 中的后台代理

c# - WPF Tab Control 强制 Scrollviewer 显示新添加的项目