Ben*_*ual 12 c# wpf scrollviewer
我有一个TreeView.现在,我想检测,如果垂直滚动条是否可见.我试试的时候
var visibility = this.ProjectTree.GetValue(ScrollViewer.VerticalScrollBarVisibilityProperty)
Run Code Online (Sandbox Code Playgroud)
(其中this.ProjectTree是TreeView)我总是获得Auto以获得可见性.
如果ScrollBar有效可见,我该如何检测?
谢谢.
Tho*_*que 16
您可以使用该ComputedVerticalScrollBarVisibility物业.但为此,您首先需要ScrollViewer在TreeView模板中找到它.为此,您可以使用以下扩展方法:
public static IEnumerable<DependencyObject> GetDescendants(this DependencyObject obj)
{
foreach (var child in obj.GetChildren())
{
yield return child;
foreach (var descendant in child.GetDescendants())
{
yield return descendant;
}
}
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
var scrollViewer = ProjectTree.GetDescendants().OfType<ScrollViewer>().First();
var visibility = scrollViewer.ComputedVerticalScrollBarVisibility;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8124 次 |
| 最近记录: |