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


C# TextPointer.InsertTextElement方法代码示例

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


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

示例1: InsertInkAtPosition

        // Inserts an InkInteropObject at a specified position.
        private TextPointer InsertInkAtPosition(TextPointer insertionPosition, InkInteropObject inkobject, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            int symbolsAddedBefore = 0;
            int symbolsAddedAfter = 0;

            // Prepare an insertion position for InlineUIContainer.
            // As an optimization, shift outside of any formatting tags to avoid
            // splitting tags below.
            while (insertionPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
                TextSchema.IsFormattingType(insertionPosition.Parent.GetType()))
            {
                insertionPosition = insertionPosition.GetNextContextPosition(LogicalDirection.Backward);
            }
            while (insertionPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd &&
                TextSchema.IsFormattingType(insertionPosition.Parent.GetType()))
            {
                insertionPosition = insertionPosition.GetNextContextPosition(LogicalDirection.Forward);
            }

            // If we need to, split the current parent TextElement and prepare
            // a suitable home for an InlineUIContainer.
            if (!TextSchema.IsValidParent(insertionPosition.Parent.GetType(), typeof(InlineUIContainer)))
            {
                insertionPosition = TextRangeEditTables.EnsureInsertionPosition(insertionPosition, out symbolsAddedBefore, out symbolsAddedAfter);
                Invariant.Assert(insertionPosition.Parent is Run, "position must be in Run scope");

                insertionPosition = TextRangeEdit.SplitElement(insertionPosition);
                // We need to remember how many symbols were added into addition
                // to the InlineUIContainer itself.
                // Account for the two element edges just added.
                symbolsAddedBefore += 1;
                symbolsAddedAfter += 1;
            }

            // Create an InlineUIContainer.
            InlineUIContainer inlineUIContainer = new InlineUIContainer(inkobject);

            change.start = ((ITextPointer)insertionPosition).Offset - symbolsAddedBefore;
            change.oldEnd = change.start;

            // Insert it into the insertionPosition.  This adds 3 symbols.
            insertionPosition.InsertTextElement(inlineUIContainer);

            change.newEnd = change.start + symbolsAddedBefore + inlineUIContainer.SymbolCount + symbolsAddedAfter;

            // Return a position after the inserted object.
            return inlineUIContainer.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
        }
开发者ID:mind0n,项目名称:hive,代码行数:49,代码来源:TextStore.cs

示例2: InsertLineBreak

        /// <summary>
        /// Insert a LineBreak element at the given position. 
        /// If position's parent is a Paragraph or Span, simply insert a LineBreak element at this position.
        /// Otherwise, ensure insertion position and insert a LineBreak element at insertion position in text content.
        /// </summary>
        /// <param name="position"> 
        /// </param>
        /// <returns> 
        /// TextPointer positioned in the beginning of a Run immediately following a LineBreak inserted. 
        /// </returns>
        internal static TextPointer InsertLineBreak(TextPointer position) 
        {
            if (!TextSchema.IsValidChild(/*position*/position, /*childType*/typeof(LineBreak)))
            {
                // Ensure insertion position, in case position's parent is not a paragraph/span element. 
                position = TextRangeEditTables.EnsureInsertionPosition(position);
            } 
 
            if (TextSchema.IsInTextContent(position))
            { 
                // Split parent Run element, if position is inside of Run scope.
                position = SplitElement(position);
            }
 
            Invariant.Assert(TextSchema.IsValidChild(/*position*/position, /*childType*/typeof(LineBreak)),
                "position must be in valid scope now to insert a LineBreak element"); 
 
            LineBreak lineBreak = new LineBreak();
 
            position.InsertTextElement(lineBreak);

            return lineBreak.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:33,代码来源:TextRangeEdit.cs


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