TextPointer.GetPositionAtOffset Método

Definición

Devuelve un TextPointer objeto a la posición indicada por el desplazamiento especificado, en símbolos, desde el principio del contenido.

Sobrecargas

Nombre Description
GetPositionAtOffset(Int32, LogicalDirection)

Devuelve un TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, desde el principio del TextPointer actual y en la dirección especificada.

GetPositionAtOffset(Int32)

Devuelve un TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, desde el principio del TextPointeractual.

GetPositionAtOffset(Int32, LogicalDirection)

Devuelve un TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, desde el principio del TextPointer actual y en la dirección especificada.

public:
 System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset, System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointer GetPositionAtOffset(int offset, System.Windows.Documents.LogicalDirection direction);
member this.GetPositionAtOffset : int * System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer, direction As LogicalDirection) As TextPointer

Parámetros

offset
Int32

Desplazamiento, en símbolos, para el que se va a calcular y devolver la posición. Si el desplazamiento es negativo, el devuelto TextPointer precede al actual TextPointer; de lo contrario, sigue.

direction
LogicalDirection

Uno de los LogicalDirection valores que especifica la dirección lógica del devuelto TextPointer.

Devoluciones

objeto TextPointer a la posición indicada por el desplazamiento especificado, o null si el desplazamiento se extiende más allá del final del contenido.

Comentarios

Cualquiera de los siguientes se considera un símbolo:

  • Etiqueta de apertura o cierre para el TextElement elemento.

  • Elemento UIElement contenido en o InlineUIContainerBlockUIContainer. Tenga en cuenta que tal UIElement siempre se cuenta como un símbolo exactamente; ningún contenido o elemento adicional contenido de la UIElement no se cuentan como símbolos.

  • Carácter Unicode de 16 bits dentro de un elemento de texto Run .

Consulte también

Se aplica a

GetPositionAtOffset(Int32)

Devuelve un TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, desde el principio del TextPointeractual.

public:
 System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset);
public System.Windows.Documents.TextPointer GetPositionAtOffset(int offset);
member this.GetPositionAtOffset : int -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer) As TextPointer

Parámetros

offset
Int32

Desplazamiento, en símbolos, para el que se va a calcular y devolver la posición. Si el desplazamiento es negativo, la posición se calcula en la dirección lógica opuesta a la indicada por la LogicalDirection propiedad .

Devoluciones

a TextPointer la posición indicada por el desplazamiento especificado o null si no se encuentra ninguna posición correspondiente.

Ejemplos

En el ejemplo siguiente se muestra un uso para este método. En el ejemplo se usa el GetPositionAtOffset método para implementar un par de métodos, uno para calcular el desplazamiento a una posición especificada en relación con cualquier párrafo de hospedaje y el otro para devolver un TextPointer objeto a un desplazamiento especificado en un párrafo especificado.

// Returns the offset for the specified position relative to any containing paragraph.
int GetOffsetRelativeToParagraph(TextPointer position)
{
    // Adjust the pointer to the closest forward insertion position, and look for any
    // containing paragraph.
    Paragraph paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph;

    // Some positions may be not within any Paragraph; 
    // this method returns an offset of -1 to indicate this condition.
    return (paragraph == null) ? -1 : paragraph.ContentStart.GetOffsetToPosition(position);
}

// Returns a TextPointer to a specified offset into a specified paragraph. 
TextPointer GetTextPointerRelativeToParagraph(Paragraph paragraph, int offsetRelativeToParagraph)
{
    // Verify that the specified offset falls within the specified paragraph.  If the offset is
    // past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
    // Otherwise, return a TextPointer to the specified offset in the specified paragraph.
    return (offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd)) 
        ? paragraph.ContentEnd : paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph);
}
' Returns the offset for the specified position relative to any containing paragraph.
Private Function GetOffsetRelativeToParagraph(ByVal position As TextPointer) As Integer
    ' Adjust the pointer to the closest forward insertion position, and look for any
    ' containing paragraph.
    Dim paragraph As Paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph

    ' Some positions may be not within any Paragraph 
    ' this method returns an offset of -1 to indicate this condition.
    Return If((paragraph Is Nothing), -1, paragraph.ContentStart.GetOffsetToPosition(position))
End Function

' Returns a TextPointer to a specified offset into a specified paragraph. 
Private Function GetTextPointerRelativeToParagraph(ByVal paragraph As Paragraph, ByVal offsetRelativeToParagraph As Integer) As TextPointer
    ' Verify that the specified offset falls within the specified paragraph.  If the offset is
    ' past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
    ' Otherwise, return a TextPointer to the specified offset in the specified paragraph.
    Return If((offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd)), paragraph.ContentEnd, paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph))
End Function

Comentarios

Cualquiera de los siguientes se considera un símbolo:

  • Etiqueta de apertura o cierre para el TextElement elemento.

  • Elemento UIElement contenido en o InlineUIContainerBlockUIContainer. Tenga en cuenta que tal UIElement siempre se cuenta como un símbolo exactamente; ningún contenido o elemento adicional contenido de la UIElement no se cuentan como símbolos.

  • Carácter Unicode de 16 bits dentro de un elemento de texto Run .

Consulte también

Se aplica a