Exemplo n.º 1
0
        private void E_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkContentElement FE = (FrameworkContentElement)sender;

            FE.Loaded -= E_Loaded;
            FE.BringIntoView();
        }
Exemplo n.º 2
0
        public void ScrollToSelection(RichTextBox viewer)
        {
            TextPointer             t = viewer.Selection.Start;
            FrameworkContentElement e = t.Parent as FrameworkContentElement;

            if (e != null)
            {
                e.BringIntoView();
            }
        }
Exemplo n.º 3
0
        // -------------------------- GoToMark_Click --------------------------
        void GoToMark_Click(object sender, RoutedEventArgs e)
        {
            Annotation ann = null;

            if (sender is Button)
            {
                ann = ((Button)sender).Tag as Annotation;
            }
            else if (sender is MenuItem)
            {
                ann = ((MenuItem)sender).Tag as Annotation;
            }
            if (ann == null)
            {
                return;
            }

            ContentLocator cloc =
                ann.Anchors[0].ContentLocators[0] as ContentLocator;

            if (cloc == null)
            {
                return;
            }
            if (cloc.Parts.Count < 2)
            {
                return;
            }

            ContentLocatorPart cPart = cloc.Parts[1];

            if (cPart == null)
            {
                return;
            }
            if (cPart.NameValuePairs["Segment0"] != null)
            {
                string[]     charPos = cPart.NameValuePairs["Segment0"].Split(',');
                FlowDocument fd      = FDPV.Document as FlowDocument;
                TextPointer  tp      = fd.ContentStart.GetPositionAtOffset(
                    int.Parse(charPos[0]), LogicalDirection.Forward);
                if (tp == null)
                {
                    return;
                }

                FrameworkContentElement fce = tp.Parent as FrameworkContentElement;
                if (fce == null)
                {
                    return;
                }

                fce.BringIntoView();
            }
        }
Exemplo n.º 4
0
 private void _BringIntoView(FrameworkContentElement element)
 {
     if (element.IsLoaded)
     {
         element.BringIntoView();
     }
     else
     {
         element.Loaded += E_Loaded;
     }
 }
Exemplo n.º 5
0
        //<SnippetFEBringIntoView>
        void browserFrame_FragmentNavigation(object sender, FragmentNavigationEventArgs e)
        {
            object content = ((ContentControl)e.Navigator).Content;
            FrameworkContentElement fragmentElement = LogicalTreeHelper.FindLogicalNode((DependencyObject)content, e.Fragment) as FrameworkContentElement;

            if (fragmentElement != null)
            {
                // Go to fragment if found
                fragmentElement.BringIntoView();
            }
            e.Handled = true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// This helper method is used by TextRangeAdaptor to bring the range into view
        /// through multiple nested scroll providers.
        /// </summary>
        internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToTop)
        {
            // Calculate the bounding rectangle for the range
            Rect rangeBounds = Rect.Empty;

            Rect[] lineBounds = GetBoundingRectangles(start, end, false, false);
            foreach (Rect rect in lineBounds)
            {
                rangeBounds.Union(rect);
            }

            ITextView textView = GetUpdatedTextView();

            if (textView != null && !rangeBounds.IsEmpty)
            {
                // Find out the visible portion of the range.
                Rect visibleRect        = GetVisibleRectangle(textView);
                Rect rangeVisibleBounds = Rect.Intersect(rangeBounds, visibleRect);
                if (rangeVisibleBounds == rangeBounds)
                {
                    // The range is already in the view. It's probably not aligned as requested,
                    // but who cares since it's entirely visible anyway.
                    return;
                }

                // Ensure the visibility of the range.
                // BringIntoView will do most of the magic except the very first scroll
                // in order to satisfy the requested alignment.
                UIElement renderScope = textView.RenderScope;
                Visual    visual      = renderScope;
                while (visual != null)
                {
                    IScrollInfo isi = visual as IScrollInfo;
                    if (isi != null)
                    {
                        // Transform the bounding rectangle into the IScrollInfo coordinates.
                        if (visual != renderScope)
                        {
                            GeneralTransform childToParent = renderScope.TransformToAncestor(visual);
                            rangeBounds = childToParent.TransformBounds(rangeBounds);
                        }

                        if (isi.CanHorizontallyScroll)
                        {
                            isi.SetHorizontalOffset(alignToTop ? rangeBounds.Left : (rangeBounds.Right - isi.ViewportWidth));
                        }
                        if (isi.CanVerticallyScroll)
                        {
                            isi.SetVerticalOffset(alignToTop ? rangeBounds.Top : (rangeBounds.Bottom - isi.ViewportHeight));
                        }
                        break;
                    }
                    visual = VisualTreeHelper.GetParent(visual) as Visual;
                }

                FrameworkElement fe = renderScope as FrameworkElement;
                if (fe != null)
                {
                    fe.BringIntoView(rangeVisibleBounds);
                }
            }
            else
            {
                // If failed to retrive range bounds, try to Bring into view closes element.
                ITextPointer pointer = alignToTop ? start.CreatePointer() : end.CreatePointer();
                pointer.MoveToElementEdge(alignToTop ? ElementEdge.AfterStart : ElementEdge.AfterEnd);
                FrameworkContentElement element = pointer.GetAdjacentElement(LogicalDirection.Backward) as FrameworkContentElement;
                if (element != null)
                {
                    element.BringIntoView();
                }
            }
        }
Exemplo n.º 7
0
        // Token: 0x060065C7 RID: 26055 RVA: 0x001C84A0 File Offset: 0x001C66A0
        internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToTop)
        {
            Rect rect = Rect.Empty;

            Rect[] boundingRectangles = this.GetBoundingRectangles(start, end, false, false);
            foreach (Rect rect2 in boundingRectangles)
            {
                rect.Union(rect2);
            }
            ITextView updatedTextView = this.GetUpdatedTextView();

            if (updatedTextView != null && !rect.IsEmpty)
            {
                Rect visibleRectangle = this.GetVisibleRectangle(updatedTextView);
                Rect rect3            = Rect.Intersect(rect, visibleRectangle);
                if (rect3 == rect)
                {
                    return;
                }
                UIElement renderScope = updatedTextView.RenderScope;
                Visual    visual      = renderScope;
                while (visual != null)
                {
                    IScrollInfo scrollInfo = visual as IScrollInfo;
                    if (scrollInfo != null)
                    {
                        if (visual != renderScope)
                        {
                            GeneralTransform generalTransform = renderScope.TransformToAncestor(visual);
                            rect = generalTransform.TransformBounds(rect);
                        }
                        if (scrollInfo.CanHorizontallyScroll)
                        {
                            scrollInfo.SetHorizontalOffset(alignToTop ? rect.Left : (rect.Right - scrollInfo.ViewportWidth));
                        }
                        if (scrollInfo.CanVerticallyScroll)
                        {
                            scrollInfo.SetVerticalOffset(alignToTop ? rect.Top : (rect.Bottom - scrollInfo.ViewportHeight));
                            break;
                        }
                        break;
                    }
                    else
                    {
                        visual = (VisualTreeHelper.GetParent(visual) as Visual);
                    }
                }
                FrameworkElement frameworkElement = renderScope as FrameworkElement;
                if (frameworkElement != null)
                {
                    frameworkElement.BringIntoView(rect3);
                    return;
                }
            }
            else
            {
                ITextPointer textPointer = alignToTop ? start.CreatePointer() : end.CreatePointer();
                textPointer.MoveToElementEdge(alignToTop ? ElementEdge.AfterStart : ElementEdge.AfterEnd);
                FrameworkContentElement frameworkContentElement = textPointer.GetAdjacentElement(LogicalDirection.Backward) as FrameworkContentElement;
                if (frameworkContentElement != null)
                {
                    frameworkContentElement.BringIntoView();
                }
            }
        }