System.Windows.Controls.ScrollViewer.OnScrollBarVisibilityChanged C# (CSharp) Method

OnScrollBarVisibilityChanged() private static method

Called when the HorizontalScrollBarVisibility/VerticalScrollBarVisibility property has changed.
private static OnScrollBarVisibilityChanged ( DependencyObject d, DependencyPropertyChangedEventArgs e ) : void
d DependencyObject The DependencyObject for which the property changed.
e DependencyPropertyChangedEventArgs Provides data for DependencyPropertyChangedEventArgs.
return void
        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); 
                }
            } 
        }