TextPointer.IsInSameDocument Method

Indicates whether the specified position is in the same text container as the current position.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)

public bool IsInSameDocument(
	TextPointer textPosition
)

Parameters

textPosition
Type: System.Windows.Documents.TextPointer
A TextPointer that specifies a position to compare to the current position.

Return Value

Type: System.Boolean
true if textPosition indicates a position that is in the same text container as the current position; otherwise, false.

ExceptionCondition
ArgumentNullException

textPosition is null.

Most operations that involve multiple TextPointer instances are only valid if the instances in question indicate positions that are in the same text container scope. For example the CompareTo and GetOffsetToPosition methods cannot be used with a TextPointer to a position outside of the text container associated with the current position. Use this method to verify that a specified TextPointer is compatible with the current position for such operations.

The following example demonstrates a use for this method. The example uses the IsInSameDocument method to check whether a specified TextPointer is positioned between two other specified TextPointer instances in a situation when there is no guarantee that all three positions belong to the same text container.


// 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;
}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft