I have a TreeView. Now, I want to detect, if the vertical Scrollbar is visible or not. When I try it with
var visibility = this.ProjectTree.GetValue(ScrollViewer.VerticalScrollBarVisibilityProperty)
(where this.ProjectTree is the TreeView) I get always Auto for visibility.
How can I do this to detect, if the ScrollBar is effectiv visible or not?
Thanks.
ComputedVerticalScrollBarVisibility instead of VerticalScrollBarVisibility
VerticalScrollBarVisibility sets or gets the behavior, whereas the ComputedVerticalScrollBarVisibility gives you the actual status.
http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.computedverticalscrollbarvisibility(v=vs.110).aspx
You cannot access this property the same way you did in your code example, see Thomas Levesque's answer for that :)
You can use the
ComputedVerticalScrollBarVisibility
property. But for that, you first need to find theScrollViewer
in theTreeView
's template. To do that, you can use the following extension method:Use it like this:
Easiest approach I've found is to simply subscribe to the
ScrollChanged
event which is part of the attached propertyScrollViewer
, for example:Codebehind:
For some reason IntelliSense didn't show me the event but it works.