本文整理汇总了C#中System.Windows.Documents.TextPointer.MoveToPosition方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.MoveToPosition方法的具体用法?C# TextPointer.MoveToPosition怎么用?C# TextPointer.MoveToPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.MoveToPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteEquiScopedContent
/// <summary>
/// Deletes all equi-scoped segments of content from start TextPointer
/// up to fragment root. Thus clears one half of a fragment.
/// The other half remains untouched.
/// All elements whose boundaries are crossed by this range
/// remain in the tree (except for emptied formatting elements).
/// </summary>
/// <param name="start">
/// A position from which content clearinng starts.
/// All content segments between this position and a fragment
/// root will be deleted.
/// </param>
/// <param name="end">
/// A position indicating the other boundary of a fragment.
/// This position is used for fragment root identification.
/// </param>
private static void DeleteEquiScopedContent(TextPointer start, TextPointer end)
{
// Validate parameters
Invariant.Assert(start != null, "null check: start");
Invariant.Assert(end != null, "null check: end");
if (start.CompareTo(end) == 0)
{
return;
}
if (start.Parent == end.Parent)
{
DeleteContentBetweenPositions(start, end);
return;
}
// Identify directional parameters
LogicalDirection direction;
LogicalDirection oppositeDirection;
TextPointerContext enterScopeSymbol;
TextPointerContext leaveScopeSymbol;
ElementEdge edgeBeforeElement;
ElementEdge edgeAfterElement;
if (start.CompareTo(end) < 0)
{
direction = LogicalDirection.Forward;
oppositeDirection = LogicalDirection.Backward;
enterScopeSymbol = TextPointerContext.ElementStart;
leaveScopeSymbol = TextPointerContext.ElementEnd;
edgeBeforeElement = ElementEdge.BeforeStart;
edgeAfterElement = ElementEdge.AfterEnd;
}
else
{
direction = LogicalDirection.Backward;
oppositeDirection = LogicalDirection.Forward;
enterScopeSymbol = TextPointerContext.ElementEnd;
leaveScopeSymbol = TextPointerContext.ElementStart;
edgeBeforeElement = ElementEdge.AfterEnd;
edgeAfterElement = ElementEdge.BeforeStart;
}
// previousPosition will store a location where nondeleted content starts
TextPointer previousPosition = new TextPointer(start);
// nextPosition runs toward other end until level change -
// so that we could delete all content from previousPosition
// to nextPosition at once.
TextPointer nextPosition = new TextPointer(start);
// Run nextPosition forward until the very end of affected range
while (nextPosition.CompareTo(end) != 0)
{
Invariant.Assert(direction == LogicalDirection.Forward && nextPosition.CompareTo(end) < 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) > 0,
"Inappropriate position ordering");
Invariant.Assert(previousPosition.Parent == nextPosition.Parent, "inconsistent position Parents: previous and next");
TextPointerContext pointerContext = nextPosition.GetPointerContext(direction);
if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.EmbeddedElement)
{
// Add this run to a collection of equi-scoped content
nextPosition.MoveToNextContextPosition(direction);
// Check if we went too far and return a little to end if necessary
if (direction == LogicalDirection.Forward && nextPosition.CompareTo(end) > 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) < 0)
{
Invariant.Assert(nextPosition.Parent == end.Parent, "inconsistent poaition Parents: next and end");
nextPosition.MoveToPosition(end);
break;
}
}
else if (pointerContext == enterScopeSymbol)
{
// Jump over the element and continue collecting equi-scoped content
nextPosition.MoveToNextContextPosition(direction);
((ITextPointer)nextPosition).MoveToElementEdge(edgeAfterElement);
// If our range crosses the element then we stop before its opening tag
if (direction == LogicalDirection.Forward && nextPosition.CompareTo(end) >= 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) <= 0)
{
nextPosition.MoveToNextContextPosition(oppositeDirection);
((ITextPointer)nextPosition).MoveToElementEdge(edgeBeforeElement);
break;
//.........这里部分代码省略.........
示例2: GetListItemIndex
//--------------------------------------------------------------------
//
// Internal Methods
//
//--------------------------------------------------------------------
#region Internal Methods
/// <summary>
/// Returns the integer "index" of a specified ListItem that is an immediate child of
/// this List. This index is defined to be a sequential counter of ListElementItems only
/// (skipping other elements) among this List's immediate children.
///
/// The list item index of the first child of type ListItem is specified by
/// this.StartListIndex, which has a default value of 1.
///
/// The index returned by this method is used in the formation of some ListItem
/// markers such as "(b)" and "viii." (as opposed to others, like disks and wedges,
/// which are not sequential-position-dependent).
/// </summary>
/// <param name="item">The item whose index is to be returned.</param>
/// <returns>Returns the index of a specified ListItem.</returns>
internal int GetListItemIndex(ListItem item)
{
// Check for valid arg
if (item == null)
{
throw new ArgumentNullException("item");
}
if (item.Parent != this)
{
throw new InvalidOperationException(SR.Get(SRID.ListElementItemNotAChildOfList));
}
// Count ListItem siblings (not other element types) back to first item.
int itemIndex = StartIndex;
TextPointer textNav = new TextPointer(this.ContentStart);
while (textNav.CompareTo(this.ContentEnd) != 0)
{
// ListItem is a content element, so look for ElementStart runs only
if (textNav.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
{
DependencyObject element = textNav.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
if (element is ListItem)
{
if (element == item)
{
break;
}
if (itemIndex < int.MaxValue)
{
++itemIndex;
}
}
// Skip entire content element content, because we are looking
// only for immediate children.
textNav.MoveToPosition(((TextElement)element).ElementEnd);
}
else
{
textNav.MoveToNextContextPosition(LogicalDirection.Forward);
}
}
return itemIndex;
}