当前位置: 首页>>代码示例>>C#>>正文


C# TextPointer.GetNonMergeableInlineAncestor方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextPointer.GetNonMergeableInlineAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetNonMergeableInlineAncestor方法的具体用法?C# TextPointer.GetNonMergeableInlineAncestor怎么用?C# TextPointer.GetNonMergeableInlineAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextPointer的用法示例。


在下文中一共展示了TextPointer.GetNonMergeableInlineAncestor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Span

        /// <summary>
        /// Creates a new Span instance covering existing content.
        /// </summary>
        /// <param name="start">
        /// Start position of the new Span.
        /// </param>
        /// <param name="end">
        /// End position of the new Span.
        /// </param>
        /// <remarks>
        /// start and end must both be parented by the same Paragraph, otherwise
        /// the method will raise an ArgumentException.
        /// </remarks>
        public Span(TextPointer start, TextPointer end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }
            if (end == null)
            {
                throw new ArgumentNullException("start");
            }
            if (start.TextContainer != end.TextContainer)
            {
                throw new ArgumentException(SR.Get(SRID.InDifferentTextContainers, "start", "end"));
            }
            if (start.CompareTo(end) > 0)
            {
                throw new ArgumentException(SR.Get(SRID.BadTextPositionOrder, "start", "end"));
            }

            start.TextContainer.BeginChange();
            try
            {
                start = TextRangeEditTables.EnsureInsertionPosition(start);
                Invariant.Assert(start.Parent is Run);
                end = TextRangeEditTables.EnsureInsertionPosition(end);
                Invariant.Assert(end.Parent is Run);

                if (start.Paragraph != end.Paragraph)
                {
                    throw new ArgumentException(SR.Get(SRID.InDifferentParagraphs, "start", "end"));
                }

                // If start or end positions have a Hyperlink ancestor, we cannot split them.
                Inline nonMergeableAncestor;
                if ((nonMergeableAncestor = start.GetNonMergeableInlineAncestor()) != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotSplitElement, nonMergeableAncestor.GetType().Name));
                }
                if ((nonMergeableAncestor = end.GetNonMergeableInlineAncestor()) != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotSplitElement, nonMergeableAncestor.GetType().Name));
                }

                TextElement commonAncestor = TextElement.GetCommonAncestor((TextElement)start.Parent, (TextElement)end.Parent);

                while (start.Parent != commonAncestor)
                {
                    start = SplitElement(start);
                }
                while (end.Parent != commonAncestor)
                {
                    end = SplitElement(end);
                }

                if (start.Parent is Run)
                {
                    start = SplitElement(start);
                }
                if (end.Parent is Run)
                {
                    end = SplitElement(end);
                }

                Invariant.Assert(start.Parent == end.Parent);
                Invariant.Assert(TextSchema.IsValidChild(/*position*/start, /*childType*/typeof(Span)));

                this.Reposition(start, end);
            }
            finally
            {
                start.TextContainer.EndChange();
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:86,代码来源:Span.cs

示例2: InsertParagraphBreak

        /// <summary>
        /// Insert paragraph break at the End position of a range. 
        /// It only affects specified position - not a whole range.
        /// So it is essentially TextContainer-level (low-level) operation.
        /// </summary>
        /// <param name="position"> 
        /// Position at which the content should be split into two paragraphs.
        /// After the operation breakPosition moved into a beginning of the 
        /// second paragraph after all opening tags created by splitting 
        /// (this position may be not-normalized though if there are some
        /// other opening formatting tags following the position - this may 
        /// be important for reading from xml when pasting point was before
        /// some opening formatting tags but after non-whitespace characters).
        /// </param>
        /// <param name="moveIntoSecondParagraph"> 
        /// True means that resulting TextPointer must be moved into the second paragraph.
        /// False means that resulting pointer remains in a non-normalized position 
        /// between two paragraphs (or list items). 
        /// </param>
        /// <remarks> 
        /// This function could be implemented from TextContainer class.
        /// </remarks>
        /// <returns>
        /// If position passed was in paragraph content, returns a TextPointer 
        /// at an ContentStart of the second paragraph.
        /// If position passed was at a structural boundary (specifically table row end, 
        /// block ui container start/end or before first table in a collection of blocks), 
        /// then an implicit paragraph is inserted at the boundary and a position at its
        /// ContentStart is returned. 
        /// </returns>
        internal static TextPointer InsertParagraphBreak(TextPointer position, bool moveIntoSecondParagraph)
        {
            Invariant.Assert(position.TextContainer.Parent == null || TextSchema.IsValidChildOfContainer(position.TextContainer.Parent.GetType(), typeof(Paragraph))); 

            bool structuralBoundaryCrossed = TextPointerBase.IsAtRowEnd(position) || 
                TextPointerBase.IsBeforeFirstTable(position) || 
                TextPointerBase.IsInBlockUIContainer(position);
 
            if (position.Paragraph == null)
            {
                // Ensure insertion position, in case original position is not in text content.
                position = TextRangeEditTables.EnsureInsertionPosition(position); 
            }
 
            Inline ancestor = position.GetNonMergeableInlineAncestor(); 
            if (ancestor != null)
            { 
                Invariant.Assert(TextPointerBase.IsPositionAtNonMergeableInlineBoundary(position), "Position must be at hyperlink boundary!");

                // If position is at a hyperlink boundary, move outside hyperlink element scope
                // so that we can successfuly split formatting elements upto paragraph ancestor. 

                position = position.IsAtNonMergeableInlineStart ? ancestor.ElementStart : ancestor.ElementEnd; 
            } 

            Paragraph paragraph = position.Paragraph; 
            if (paragraph == null)
            {
                // At this point, we expect we're working in a fragment of Inlines only.
                Invariant.Assert(position.TextContainer.Parent == null); 

                // Add a parent Paragraph to split. 
                paragraph = new Paragraph(); 
                paragraph.Reposition(position.DocumentStart, position.DocumentEnd);
            } 

            if (structuralBoundaryCrossed)
            {
                // In case structural boundary was crossed, an implicit paragraph was inserted in EnsureInsertionPosition. 
                // No need to insert another paragraph break.
                return position; 
            } 

            TextPointer breakPosition = position; 

            // Split all inline elements up to this paragraph
            breakPosition = SplitFormattingElements(breakPosition, /*keepEmptyFormatting:*/true);
            Invariant.Assert(breakPosition.Parent == paragraph, "breakPosition must be in paragraph scope after splitting formatting elements"); 

            // Decide whether we need to split ListItem around this paragraph (if any). 
            // We are splitting a list item if this paragraph is the only paragraph in a list item. 
            // Otherwise we simply produce new paragraphs within the same list item.
            bool needToSplitListItem = TextPointerBase.GetImmediateListItem(paragraph.ContentStart) != null; 

            breakPosition = SplitElement(breakPosition);

            // Also split ListItem (if any) 
            if (needToSplitListItem)
            { 
                Invariant.Assert(breakPosition.Parent is ListItem, "breakPosition must be in ListItem scope"); 
                breakPosition = SplitElement(breakPosition);
            } 

            if (moveIntoSecondParagraph)
            {
                // Move breakPosition inside of the second paragraph 
                while (!(breakPosition.Parent is Paragraph) && breakPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
                { 
                    breakPosition = breakPosition.GetNextContextPosition(LogicalDirection.Forward); 
                }
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeEdit.cs


注:本文中的System.Windows.Documents.TextPointer.GetNonMergeableInlineAncestor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。