TextPointer.GetPositionAtOffset Metodo

Definizione

Restituisce un oggetto TextPointer alla posizione indicata dall'offset specificato, in simboli, dall'inizio del contenuto.

Overload

Nome Descrizione
GetPositionAtOffset(Int32, LogicalDirection)

Restituisce un TextPointer alla posizione indicata dall'offset specificato, in simboli, dall'inizio del TextPointer corrente e nella direzione specificata.

GetPositionAtOffset(Int32)

Restituisce un TextPointer alla posizione indicata dall'offset specificato, in simboli, dall'inizio del TextPointercorrente.

GetPositionAtOffset(Int32, LogicalDirection)

Restituisce un TextPointer alla posizione indicata dall'offset specificato, in simboli, dall'inizio del TextPointer corrente e nella direzione specificata.

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

Parametri

offset
Int32

Offset, in simboli, per il quale calcolare e restituire la posizione. Se l'offset è negativo, l'oggetto restituito TextPointer precede l'oggetto corrente TextPointer; in caso contrario, segue.

direction
LogicalDirection

Uno dei LogicalDirection valori che specifica la direzione logica dell'oggetto restituito TextPointer.

Valori restituiti

Oggetto TextPointer alla posizione indicata dall'offset specificato o null se l'offset si estende oltre la fine del contenuto.

Commenti

Uno dei seguenti è considerato un simbolo:

  • Tag di apertura o chiusura per l'elemento TextElement .

  • Elemento UIElement contenuto in un InlineUIContainer oggetto o BlockUIContainer. Si noti che tale UIElement viene sempre conteggiato come esattamente un simbolo; qualsiasi contenuto o elemento aggiuntivo contenuto dall'UIElement non viene conteggiato come simboli.

  • Carattere Unicode a 16 bit all'interno di un elemento di testo Run .

Vedi anche

Si applica a

GetPositionAtOffset(Int32)

Restituisce un TextPointer alla posizione indicata dall'offset specificato, in simboli, dall'inizio del TextPointercorrente.

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

Parametri

offset
Int32

Offset, in simboli, per il quale calcolare e restituire la posizione. Se l'offset è negativo, la posizione viene calcolata nella direzione logica opposta a quella indicata dalla LogicalDirection proprietà .

Valori restituiti

Oggetto TextPointer alla posizione indicata dall'offset specificato o null se non è possibile trovare alcuna posizione corrispondente.

Esempio

Nell'esempio seguente viene illustrato un utilizzo per questo metodo. Nell'esempio viene utilizzato il GetPositionAtOffset metodo per implementare una coppia di metodi, uno per calcolare l'offset in una posizione specificata rispetto a qualsiasi paragrafo host e l'altro per restituire un TextPointer oggetto a un offset specificato in un paragrafo specificato.

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

Commenti

Uno dei seguenti è considerato un simbolo:

  • Tag di apertura o chiusura per l'elemento TextElement .

  • Elemento UIElement contenuto in un InlineUIContainer oggetto o BlockUIContainer. Si noti che tale UIElement viene sempre conteggiato come esattamente un simbolo; qualsiasi contenuto o elemento aggiuntivo contenuto dall'UIElement non viene conteggiato come simboli.

  • Carattere Unicode a 16 bit all'interno di un elemento di testo Run .

Vedi anche

Si applica a