How to check if a scroll (vertical or horizontal) is currently shown in WPF DataGrid? HorizontalScrollBarVisibility and VerticalScrollBarVisibility are used to set the behaviour and they are set to Auto.
+2
A:
ScrollViewer scrollview = FindVisualChild<ScrollViewer>(dataGrid);
Visibility verticalVisibility = scrollview.ComputedVerticalScrollBarVisibility;
Visibility horizontalVisibility = scrollview.ComputedHorizontalScrollBarVisibility;
ach
2010-10-21 12:05:22
I have to implement FindVisualChild myself, don't I?
brain_pusher
2010-10-21 12:25:49
Yeah, there are a number of implementations around:http://stackoverflow.com/questions/980120/finding-control-within-wpf-itemscontrol
ach
2010-10-21 12:33:27
+1
A:
Here's an implementation of FindVisualChild:
private childItem FindVisualChild<childItem>(DependencyObject obj)
where childItem : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else
{
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
Mark
2010-10-21 12:32:15