TextPointer.GetPositionAtOffset TextPointer.GetPositionAtOffset TextPointer.GetPositionAtOffset TextPointer.GetPositionAtOffset Method

Definición

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del contenido.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of content.

Sobrecargas

GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual y en la dirección especificada.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer and in the specified direction.

GetPositionAtOffset(Int32) GetPositionAtOffset(Int32) GetPositionAtOffset(Int32) GetPositionAtOffset(Int32)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer.

GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection) GetPositionAtOffset(Int32, LogicalDirection)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual y en la dirección especificada.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer and in the specified direction.

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 Int32 Int32 Int32

Un desplazamiento, en símbolos, para el que calcular y devolver la posición.An offset, in symbols, for which to calculate and return the position. Si el desplazamiento es negativo, el TextPointer devuelto precede al TextPointer actual; de lo contrario, le sigue.If the offset is negative, the returned TextPointer precedes the current TextPointer; otherwise, it follows.

direction
LogicalDirection LogicalDirection LogicalDirection LogicalDirection

Uno de los valores de LogicalDirection que especifica la dirección lógica del TextPointer devuelto.One of the LogicalDirection values that specifies the logical direction of the returned TextPointer.

Devoluciones

TextPointer a la posición indicada por el desplazamiento especificado o null si el desplazamiento se extiende más allá del final del contenido.A TextPointer to the position indicated by the specified offset, or null if the offset extends past the end of the content.

Comentarios

Cualquiera de las siguientes acciones se considera un símbolo:Any of the following is considered to be a symbol:

  • Una etiqueta inicial o final para el TextElement elemento.An opening or closing tag for the TextElement element.

  • Un UIElement elemento contenido en un InlineUIContainer o BlockUIContainer.A UIElement element contained in an InlineUIContainer or BlockUIContainer. Tenga en cuenta que tales un UIElement siempre se cuentan como exactamente un símbolo; cualquier contenido adicional o elementos que forman parte del UIElement no se cuentan como símbolos.Note that such a UIElement is always counted as exactly one symbol; any additional content or elements contained by the UIElement are not counted as symbols.

  • 16 bits UnicodeUnicode carácter dentro de un texto Run elemento.A 16-bit UnicodeUnicode character inside of a text Run element.

Consulte también:

GetPositionAtOffset(Int32) GetPositionAtOffset(Int32) GetPositionAtOffset(Int32) GetPositionAtOffset(Int32)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer.

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 Int32 Int32 Int32

Un desplazamiento, en símbolos, para el que calcular y devolver la posición.An offset, in symbols, for which to calculate and return the position. Si el desplazamiento es negativo, la posición se calcula en la dirección lógica contraria a la indicada por la propiedad LogicalDirection.If the offset is negative, the position is calculated in the logical direction opposite of that indicated by the LogicalDirection property.

Devoluciones

TextPointer a la posición indicada por el desplazamiento especificado o null si no se encuentra ninguna posición correspondiente.A TextPointer to the position indicated by the specified offset, or null if no corresponding position can be found.

Ejemplos

El ejemplo siguiente muestra un uso de este método.The following example demonstrates a use for this method. 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 con respecto a cualquier párrafo de hospedaje y el otro para devolver un TextPointer a un desplazamiento especificado en un párrafo especificado.The example uses the GetPositionAtOffset method to implement a pair of methods, one to calculate the offset to a specified position relative to any hosting paragraph, and the other to return a TextPointer to a specified offset in a specified paragraph.

// 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 las siguientes acciones se considera un símbolo:Any of the following is considered to be a symbol:

  • Una etiqueta inicial o final para el TextElement elemento.An opening or closing tag for the TextElement element.

  • Un UIElement elemento contenido en un InlineUIContainer o BlockUIContainer.A UIElement element contained in an InlineUIContainer or BlockUIContainer. Tenga en cuenta que tales un UIElement siempre se cuentan como exactamente un símbolo; cualquier contenido adicional o elementos que forman parte del UIElement no se cuentan como símbolos.Note that such a UIElement is always counted as exactly one symbol; any additional content or elements contained by the UIElement are not counted as symbols.

  • 16 bits UnicodeUnicode carácter dentro de un texto Run elemento.A 16-bit UnicodeUnicode character inside of a text Run element.

Consulte también:

Se aplica a