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


C# TextPointer.InsertParagraphBreak方法代码示例

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


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

示例1: InsertTable

        // .................................................................... 
        // 
        // Table Insertion
        // 
        // ....................................................................

        #region Table Insertion
 
        /// <summary>
        /// Inserts a table into a position specified by textRange. 
        /// </summary> 
        /// <param name="insertionPosition">
        /// Position where table must be inserted. 
        /// </param>
        /// <param name="rowCount">
        /// Number of rows generated in a table
        /// </param> 
        /// <param name="columnCount">
        /// Number of columnns generated in each row 
        /// </param> 
        /// <returns>
        /// Returns a table inserted. 
        /// </returns>
        internal static Table InsertTable(TextPointer insertionPosition, int rowCount, int columnCount)
        {
            // Inserting tables in lists is currently disabled, so check that we are not in a list 
            TextElement ancestor = insertionPosition.Parent as TextElement;
            while (ancestor != null) 
            { 
                if (ancestor is List || ancestor is Inline && !TextSchema.IsMergeableInline(ancestor.GetType()))
                { 
                    // insertionPosition is inside a List.
                    // or it is inside a Hyperlink which is a non-splittable element.
                    // Operation disabled.
                    // 
                    return null;
                } 
                ancestor = ancestor.Parent as TextElement; 
            }
 
            insertionPosition = TextRangeEditTables.EnsureInsertionPosition(insertionPosition);

            Paragraph paragraph = insertionPosition.Paragraph;
            if (paragraph == null) 
            {
                return null; 
            } 

            // Split current paragraph at insertion position 
            insertionPosition = insertionPosition.InsertParagraphBreak(); //
            paragraph = insertionPosition.Paragraph;
            Invariant.Assert(paragraph != null, "Expecting non-null paragraph at insertionPosition");
 
            // Build a table with a given number of rows and columns
            Table table = new Table(); 
            table.CellSpacing = 0; 
            TableRowGroup rowGroup = new TableRowGroup();
            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) 
            {
                TableRow row = new TableRow();

                for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) 
                {
                    TableCell cell = new TableCell(new Paragraph()); 
                    cell.BorderThickness = GetCellBorder(1, rowIndex, columnIndex, 1, 1, rowCount, columnCount); 
                    cell.BorderBrush = System.Windows.Media.Brushes.Black;
                    row.Cells.Add(cell); 
                }
                rowGroup.Rows.Add(row);
            }
            table.RowGroups.Add(rowGroup); 

            // Insert a table before the second of split paragraphs 
            paragraph.SiblingBlocks.InsertBefore(paragraph, table); 

            return table; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:77,代码来源:TextRangeEditTables.cs

示例2: InsertBlockWithinParagraph

        private static void InsertBlockWithinParagraph(Paragraph origP, TextPointer _caretPosition, Block objectToInsert)
        {
            if (IsParagraphEmpty(origP))
            {
                FlowDocument fd = origP.Parent as FlowDocument;
                if (fd != null)
                {
                    fd.Blocks.InsertAfter(origP, objectToInsert);
                    fd.Blocks.Remove(origP);
                    return;
                }

                ListItem li = origP.Parent as ListItem;
                if (li != null)
                {
                    li.Blocks.InsertAfter(origP, objectToInsert);
                    li.Blocks.Remove(origP);
                    return;
                }
            }

            _caretPosition.InsertParagraphBreak();
            origP.SiblingBlocks.InsertAfter(origP, objectToInsert);
        }
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:24,代码来源:Util.cs


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