本文整理汇总了C#中System.Windows.Documents.StaticTextPointer.CreateDynamicTextPointer方法的典型用法代码示例。如果您正苦于以下问题:C# StaticTextPointer.CreateDynamicTextPointer方法的具体用法?C# StaticTextPointer.CreateDynamicTextPointer怎么用?C# StaticTextPointer.CreateDynamicTextPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.StaticTextPointer
的用法示例。
在下文中一共展示了StaticTextPointer.CreateDynamicTextPointer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureParentPosition
/// <summary>
/// Sets parentPosition to be a valid TextPointer in the parent document. This could either
/// be the textPosition passed in (if its already on the parent document) or a conversion
/// of the textPosition passed in.
/// </summary>
/// <returns>whether or not parentPosition is valid and should be used</returns>
private bool EnsureParentPosition(StaticTextPointer textPosition, LogicalDirection direction, out StaticTextPointer parentPosition)
{
// Simple case - textPosition is already in the parent TextContainer
parentPosition = textPosition;
// If textPosition is on a child TextContainer, we convert it
if (textPosition.TextContainer.Highlights != this)
{
// This case can't be converted so return false, out parameter should not be used
if (textPosition.GetPointerContext(direction) == TextPointerContext.None)
return false;
// Turn the textPosition (which should be in the scope of a FixedDocument)
// into a position in the scope of the DocumentSequence.
ITextPointer dynamicTextPointer = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward);
ITextPointer parentTextPointer = ((DocumentSequenceTextContainer)this.TextContainer).MapChildPositionToParent(dynamicTextPointer);
Debug.Assert(parentTextPointer != null);
parentPosition = parentTextPointer.CreateStaticPointer();
}
// Returning true - either we started with a parent position or we converted to one
return true;
}
示例2: GetStaticPositionInChildContainer
/// <summary>
/// Conversion from a StaticTextPointer on a DocumentSequence into a StaticTextPointer
/// on a specified FixedDocument. If the conversion results in a pointer on a different
/// FixedDocument then we return one end of the FixedDocument (based on direction).
/// </summary>
/// <param name="textPosition">position in a DocumentSequence to convert</param>
/// <param name="direction">direction of the desired conversion</param>
/// <param name="originalPosition">original pointer from FixedDocument</param>
private StaticTextPointer GetStaticPositionInChildContainer(StaticTextPointer textPosition, LogicalDirection direction, StaticTextPointer originalPosition)
{
StaticTextPointer parentTextPointer = StaticTextPointer.Null;
if (!textPosition.IsNull)
{
DocumentSequenceTextPointer parentChangePosition = textPosition.CreateDynamicTextPointer(LogicalDirection.Forward) as DocumentSequenceTextPointer;
Debug.Assert(parentChangePosition != null);
// If the DocSequence position translates into a position in a different FixedDocument than
// the original request, we return an end of the original FixedDocument (which end depends on direction)
ITextPointer childTp = parentChangePosition.ChildPointer;
if (childTp.TextContainer != originalPosition.TextContainer)
{
// If the position we started searching from is highlighted, cut the highlight
// at the end of the text container. Otherwise return null (the highlight must
// start in the next document).
if (IsContentHighlighted(originalPosition, direction))
{
childTp = direction == LogicalDirection.Forward ?
originalPosition.TextContainer.End
: originalPosition.TextContainer.Start;
parentTextPointer = childTp.CreateStaticPointer();
}
else
{
parentTextPointer = StaticTextPointer.Null;
}
}
else
{
parentTextPointer = childTp.CreateStaticPointer();
}
}
return parentTextPointer;
}