// TODO: this API should go on UIElement. internal void StartBringIntoView(UIElement element, double alignmentX, double alignmentY, double offsetX, double offsetY, bool animate) { m_pendingBringIntoView = new BringIntoViewState( element, alignmentX, alignmentY, offsetX, offsetY, animate); }
/// <summary> /// Makes sure the target is visible in the client area. May cause navigation /// to a different page. /// </summary> /// <param name="args">RequestBringIntoViewEventArgs indicates the element and region to scroll into view.</param> private void HandleRequestBringIntoView(RequestBringIntoViewEventArgs args) { DependencyObject child; DependencyObject parent; ContentPosition contentPosition; BringIntoViewState bringIntoViewState; DynamicDocumentPaginator documentPaginator; Rect targetRect = Rect.Empty; if (args != null && args.TargetObject != null && _document is DependencyObject) { // If the passed in object is a logical child of DocumentViewer's Document, // attempt to make it visible now. // Special case: TargetObject is the document itself. Then scroll to the top (page 1). // This supports navigating from baseURI#anchor to just baseURI. parent = _document as DependencyObject; if (args.TargetObject == _document) { OnGoToPageCommand(1); args.Handled = true; // Mark the event as handled. } else { // Verify if TargetObject is in fact a child of Document. child = args.TargetObject; while (child != null && child != parent) { // Skip elements in the control's template (if such exists) and // walk up logical tree to find if the focused element is within // the document. FrameworkElement fe = child as FrameworkElement; if (fe != null && fe.TemplatedParent != null) { child = fe.TemplatedParent; } else { child = LogicalTreeHelper.GetParent(child); } } if (child != null) { // Special case UIElements already connected to visual tree. if (args.TargetObject is UIElement) { UIElement targetObject = (UIElement)args.TargetObject; if (VisualTreeHelper.IsAncestorOf(this, targetObject)) { targetRect = args.TargetRect; if (targetRect.IsEmpty) { targetRect = new Rect(targetObject.RenderSize); } GeneralTransform transform = targetObject.TransformToAncestor(this); targetRect = transform.TransformBounds(targetRect); targetRect.IntersectsWith(new Rect(this.RenderSize)); } } // If target is not already visible, bring appropriate page into view. if (targetRect.IsEmpty) { // Get content position for given target. documentPaginator = _document.DocumentPaginator as DynamicDocumentPaginator; if (documentPaginator != null) { contentPosition = documentPaginator.GetObjectPosition(args.TargetObject); if (contentPosition != null && contentPosition != ContentPosition.Missing) { // Asynchronously retrieve PageNumber for given ContentPosition. bringIntoViewState = new BringIntoViewState(this, contentPosition, args.TargetObject, args.TargetRect); documentPaginator.GetPageNumberAsync(contentPosition, bringIntoViewState); } } } args.Handled = true; // Mark the event as handled. } } if (args.Handled) { // Create new BringIntoView request for this element, so // if there is an ancestor handling BringIntoView, it can // react appropriately and bring this element into view. if (targetRect.IsEmpty) { BringIntoView(); } else { BringIntoView(targetRect); } } } }
public ItemsRepeaterScrollHost() { m_pendingBringIntoView = new BringIntoViewState(this); }