本文整理汇总了C#中System.Windows.Documents.TextPointer.CreatePointer方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.CreatePointer方法的具体用法?C# TextPointer.CreatePointer怎么用?C# TextPointer.CreatePointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.CreatePointer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeFlowDirection
// Merges Spans or Runs with equal FlowDirection that border at a given position.
internal static void MergeFlowDirection(TextPointer position)
{
TextPointerContext backwardContext = position.GetPointerContext(LogicalDirection.Backward);
TextPointerContext forwardContext = position.GetPointerContext(LogicalDirection.Forward);
if (!(backwardContext == TextPointerContext.ElementStart || backwardContext == TextPointerContext.ElementEnd) &&
!(forwardContext == TextPointerContext.ElementStart || forwardContext == TextPointerContext.ElementEnd))
{
// Early out if position is not at an Inline border.
return;
}
// Find the common ancestor of the two adjacent content runs.
while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
TextSchema.IsMergeableInline(position.Parent.GetType()))
{
position = ((Inline)position.Parent).ElementStart;
}
while (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd &&
TextSchema.IsMergeableInline(position.Parent.GetType()))
{
position = ((Inline)position.Parent).ElementEnd;
}
TextElement commonAncestor = position.Parent as TextElement;
if (!(commonAncestor is Span || commonAncestor is Paragraph))
{
// Don't try to merge across Block boundaries.
return;
}
// Find the previous content.
TextPointer previousPosition = position.CreatePointer();
while (previousPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementEnd &&
TextSchema.IsMergeableInline(previousPosition.GetAdjacentElement(LogicalDirection.Backward).GetType()))
{
previousPosition = ((Inline)previousPosition.GetAdjacentElement(LogicalDirection.Backward)).ContentEnd;
}
Run previousRun = previousPosition.Parent as Run;
// Find the next content.
TextPointer nextPosition = position.CreatePointer();
while (nextPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart &&
TextSchema.IsMergeableInline(nextPosition.GetAdjacentElement(LogicalDirection.Forward).GetType()))
{
nextPosition = ((Inline)nextPosition.GetAdjacentElement(LogicalDirection.Forward)).ContentStart;
}
Run nextRun = nextPosition.Parent as Run;
if (previousRun == null || previousRun.IsEmpty || nextRun == null || nextRun.IsEmpty)
{
// No text to make the merge meaningful.
return;
}
FlowDirection midpointFlowDirection = (FlowDirection)commonAncestor.GetValue(FrameworkElement.FlowDirectionProperty);
FlowDirection previousFlowDirection = (FlowDirection)previousRun.GetValue(FrameworkElement.FlowDirectionProperty);
FlowDirection nextFlowDirection = (FlowDirection)nextRun.GetValue(FrameworkElement.FlowDirectionProperty);
// If the previous and next content have the same FlowDirection, but their
// common ancestor differs, we want to merge them.
if (previousFlowDirection == nextFlowDirection &&
previousFlowDirection != midpointFlowDirection)
{
// Expand the context out to include any scoping Spans with local FlowDirection.
Inline scopingPreviousInline = GetScopingFlowDirectionInline(previousRun);
Inline scopingNextInline = GetScopingFlowDirectionInline(nextRun);
// Set a single FlowDirection Span over the whole lot of it.
SetStructuralInlineProperty(scopingPreviousInline.ElementStart, scopingNextInline.ElementEnd, FrameworkElement.FlowDirectionProperty, previousFlowDirection);
}
}
示例2: MergeListsAroundNormalizedPosition
/// <summary>
/// Like MergeLists, but will search over formatting elements when
/// looking for Lists to merge.
/// </summary>
internal static bool MergeListsAroundNormalizedPosition(TextPointer mergePosition)
{
// Search forward for a List to merge with.
TextPointer navigator = mergePosition.CreatePointer();
while (navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
{
navigator.MoveToNextContextPosition(LogicalDirection.Forward);
}
bool merged = MergeLists(navigator);
// Search backward for a List to merge with.
if (!merged)
{
navigator.MoveToPosition(mergePosition);
while (navigator.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
navigator.MoveToNextContextPosition(LogicalDirection.Backward);
}
merged = MergeLists(navigator);
}
return merged;
}
示例3: CreateImplicitRun
// Helper for EnsureInsertionPosition, inserts a Run element at this position.
private static TextPointer CreateImplicitRun(TextPointer position)
{
TextPointer insertionPosition;
if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward) is Run)
{
insertionPosition = position.CreatePointer();
insertionPosition.MoveToNextContextPosition(LogicalDirection.Forward);
insertionPosition.Freeze();
}
else if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Backward) is Run)
{
insertionPosition = position.CreatePointer();
insertionPosition.MoveToNextContextPosition(LogicalDirection.Backward);
insertionPosition.Freeze();
}
else
{
Run implicitRun = Run.CreateImplicitRun(position.Parent);
implicitRun.Reposition(position, position);
insertionPosition = implicitRun.ContentStart.GetFrozenPointer(position.LogicalDirection); // return a position with the same orientation inside a Run
}
return insertionPosition;
}