本文整理汇总了C#中System.Windows.Documents.Block.RepositionWithContent方法的典型用法代码示例。如果您正苦于以下问题:C# Block.RepositionWithContent方法的具体用法?C# Block.RepositionWithContent怎么用?C# Block.RepositionWithContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.Block
的用法示例。
在下文中一共展示了Block.RepositionWithContent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeParagraphs
// --------------------------------------------------------------------
//
// Internal Methods
//
// --------------------------------------------------------------------
#region Internal Methods
/// <summary>
/// Merges two paragraphs followinng one another.
/// The content of a second paragraph is moved into the end
/// of the first one.
/// </summary>
/// <param name="firstParagraphOrBlockUIContainer">
/// First of two merged paragraphs or BlockUIContainer.
/// </param>
/// <param name="secondParagraphOrBlockUIContainer">
/// Second of two mered paragraphs or BlockUIContainer.
/// </param>
/// <returns>
/// true if paragraphs have been merged; false if no actions where made.
/// </returns>
internal static bool MergeParagraphs(Block firstParagraphOrBlockUIContainer, Block secondParagraphOrBlockUIContainer)
{
if (!ParagraphsAreMergeable(firstParagraphOrBlockUIContainer, secondParagraphOrBlockUIContainer))
{
return false; // Cannot mearge these paragraphs.
}
// Store parent list item of a second paragraph -
// to correct its structure after the merge
ListItem secondListItem = secondParagraphOrBlockUIContainer.PreviousBlock == null ? secondParagraphOrBlockUIContainer.Parent as ListItem : null;
if (secondListItem != null && secondListItem.PreviousListItem == null && secondParagraphOrBlockUIContainer.NextBlock is List)
{
// The second paragraph is a first list item in some list.
// It has a sublists in it, so this sublist must be unindented
// to avoid double bulleted line.
List sublistOfSecondParagraph = (List)secondParagraphOrBlockUIContainer.NextBlock;
if (sublistOfSecondParagraph.ElementEnd.CompareTo(secondListItem.ContentEnd) == 0)
{
secondListItem.Reposition(null, null);
}
else
{
secondListItem.Reposition(sublistOfSecondParagraph.ElementEnd, secondListItem.ContentEnd);
}
// At this point the schema is temporaty broken: the secondParagraph and the sublistOfSecondParagraph have List as a parent
sublistOfSecondParagraph.Reposition(null, null);
// The schema is repared as to sublistOfSecondParagraph concern, but still broken for secondParagraph - must be corrected in the following code
}
// Move the second paragraph out of its wrappers separating from the first paragraph (if any).
// We can not use RepositionWithContent because it would destroy
// all pointers and ranges within a moved paragraph.
// Instead we reposition elements around the two paragraphs.
while (secondParagraphOrBlockUIContainer.ElementStart.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
TextElement parentBlock = (TextElement)secondParagraphOrBlockUIContainer.Parent;
Invariant.Assert(parentBlock != null);
Invariant.Assert(TextSchema.AllowsParagraphMerging(parentBlock.GetType()));
if (secondParagraphOrBlockUIContainer.ElementEnd.CompareTo(parentBlock.ContentEnd) == 0)
{
// Remove ancestor block if it becomes empty
parentBlock.Reposition(null, null);
}
else
{
// Move ancestor's Start after the end of our paragraph
parentBlock.Reposition(secondParagraphOrBlockUIContainer.ElementEnd, parentBlock.ContentEnd);
}
}
// Store a position after the second paragraph where list merging may be needed
TextPointer positionAfterSecondParagraph = secondParagraphOrBlockUIContainer.ElementEnd.GetFrozenPointer(LogicalDirection.Forward);
// Move the second paragraph to become an immediate following sibling of the first paragraph
while (true)
{
TextElement previousBlock = secondParagraphOrBlockUIContainer.ElementStart.GetAdjacentElement(LogicalDirection.Backward) as TextElement;
// Note: We cannot use Block.NextSibling property, because the structure is invalid during this process
Invariant.Assert(previousBlock != null);
if (previousBlock is Paragraph || previousBlock is BlockUIContainer)
{
break;
}
Invariant.Assert(TextSchema.AllowsParagraphMerging(previousBlock.GetType()));
previousBlock.Reposition(previousBlock.ContentStart, secondParagraphOrBlockUIContainer.ElementEnd);
}
// Now that paragraphs are next to each other merge them.
// If one of paragraphs is empty we will apply special logic - to preserve a formatting from a non-empty one
if (secondParagraphOrBlockUIContainer.TextRange.IsEmpty)
{
secondParagraphOrBlockUIContainer.RepositionWithContent(null);
//.........这里部分代码省略.........