private static void OnScrollBarVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ScrollViewer scrollViewer = d as ScrollViewer;
if (null != scrollViewer)
{
Debug.Assert(typeof(ScrollBarVisibility).IsInstanceOfType(e.OldValue));
Debug.Assert(typeof(ScrollBarVisibility).IsInstanceOfType(e.NewValue));
scrollViewer.InvalidateMeasure();
if (scrollViewer.ScrollInfo != null) {
scrollViewer.ScrollInfo.CanHorizontallyScroll = scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
scrollViewer.ScrollInfo.CanVerticallyScroll = scrollViewer.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
}
scrollViewer.UpdateScrollbarVisibility ();
}
else
{
ListBox listBox = d as ListBox;
if ((null != listBox) && (null != listBox.TemplateScrollViewer))
{
// Push the attached property values from ListBox to ScrollViewer because
// it's not possible to set up corresponding Bindings in OnApplyTemplate
listBox.TemplateScrollViewer.SetValue(e.Property, e.NewValue);
}
}
}