private void ScrollBarVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e) { var helper = (DependencyPropertyChangedHelper)sender; if (((Visibility)e.NewValue) == Visibility.Visible) { ScrollViewerUtilities.ScrollToProportion(_itemsGridViewScrollViewer, _scrollViewerOffsetProportion); helper.PropertyChanged -= ScrollBarVisibilityChanged; } ; if (_isPageLoading) { itemsGridView.LayoutUpdated += itemsGridView_LayoutUpdated; _isPageLoading = false; } }
private void Page_SizeChanged(object sender, SizeChangedEventArgs e) { var scrollViewer = VisualTreeUtilities.GetVisualChild <ScrollViewer>(itemsGridView); if (scrollViewer != null) { if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible && scrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible) { ScrollViewerUtilities.ScrollToProportion(scrollViewer, _scrollViewerOffsetProportion); } else { _horizontalScrollBarVisibilityEventToken = scrollViewer.RegisterPropertyChangedCallback(ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty, ScrollBarVisibilityChanged); _verticalScrollBarVisibilityEventToken = scrollViewer.RegisterPropertyChangedCallback(ScrollViewer.ComputedVerticalScrollBarVisibilityProperty, ScrollBarVisibilityChanged); } } }
void Page_SizeChanged(object sender, SizeChangedEventArgs e) { var scrollViewer = VisualTreeUtilities.GetVisualChild <ScrollViewer>(itemsGridView); if (scrollViewer != null) { if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible && scrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible) { ScrollViewerUtilities.ScrollToProportion(scrollViewer, _scrollViewerOffsetProportion); } else { DependencyPropertyChangedHelper horizontalHelper = new DependencyPropertyChangedHelper(scrollViewer, "ComputedHorizontalScrollBarVisibility"); horizontalHelper.PropertyChanged += ScrollBarVisibilityChanged; DependencyPropertyChangedHelper verticalHelper = new DependencyPropertyChangedHelper(scrollViewer, "ComputedVerticalScrollBarVisibility"); verticalHelper.PropertyChanged += ScrollBarVisibilityChanged; } } }
private void ScrollBarVisibilityChanged(DependencyObject sender, DependencyProperty dp) { if (((Visibility)sender.GetValue(dp)) == Visibility.Visible) { ScrollViewerUtilities.ScrollToProportion(_itemsGridViewScrollViewer, _scrollViewerOffsetProportion); if (_horizontalScrollBarVisibilityEventToken != 0L) { sender.UnregisterPropertyChangedCallback(dp, _horizontalScrollBarVisibilityEventToken); } if (_verticalScrollBarVisibilityEventToken != 0L) { sender.UnregisterPropertyChangedCallback(dp, _verticalScrollBarVisibilityEventToken); } } if (_isPageLoading) { itemsGridView.LayoutUpdated += ItemsGridView_LayoutUpdated; _isPageLoading = false; } }