TextPointer.IsInSameDocument(TextPointer) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指示指定位置是否与当前位置位于同一文本容器中。
public:
bool IsInSameDocument(System::Windows::Documents::TextPointer ^ textPosition);
public bool IsInSameDocument(System.Windows.Documents.TextPointer textPosition);
member this.IsInSameDocument : System.Windows.Documents.TextPointer -> bool
Public Function IsInSameDocument (textPosition As TextPointer) As Boolean
参数
- textPosition
- TextPointer
一 TextPointer 个,指定要与当前位置进行比较的位置。
返回
true 如果 textPosition 指示与当前位置位于同一文本容器中的位置,则为 ;否则为 false。
例外
textPosition 是 null。
示例
以下示例演示了此方法的用法。 该示例使用IsInSameDocument该方法检查指定是否放置在另外两个指定TextPointerTextPointer实例之间,在这种情况下,无法保证这三个位置都属于同一文本容器。
// This method first checks for compatible text container scope, and then checks whether
// a specified position is between two other specified positions.
bool IsPositionContainedBetween(TextPointer positionToTest, TextPointer start, TextPointer end)
{
// Note that without this check, an exception will be raised by CompareTo if positionToTest
// does not point to a position that is in the same text container used by start and end.
//
// This test also implicitely indicates whether start and end share a common text container.
if (!positionToTest.IsInSameDocument(start) || !positionToTest.IsInSameDocument(end))
return false;
return start.CompareTo(positionToTest) <= 0 && positionToTest.CompareTo(end) <= 0;
}
' This method first checks for compatible text container scope, and then checks whether
' a specified position is between two other specified positions.
Private Function IsPositionContainedBetween(ByVal positionToTest As TextPointer, ByVal start As TextPointer, ByVal [end] As TextPointer) As Boolean
' Note that without this check, an exception will be raised by CompareTo if positionToTest
' does not point to a position that is in the same text container used by start and end.
'
' This test also implicitely indicates whether start and end share a common text container.
If (Not positionToTest.IsInSameDocument(start)) OrElse (Not positionToTest.IsInSameDocument([end])) Then
Return False
End If
Return start.CompareTo(positionToTest) <= 0 AndAlso positionToTest.CompareTo([end]) <= 0
End Function
注解
涉及多个 TextPointer 实例的大多数操作仅在有问题的实例指示位于同一文本容器范围中的位置时有效。 例如,CompareToGetOffsetToPosition和方法不能与与当前位置关联的文本容器外部的位置一起使用TextPointer。 使用此方法验证指定 TextPointer 是否与此类操作的当前位置兼容。