AnnotationHelper.GetAnchorInfo(AnnotationService, Annotation) Metodo

Definizione

Restituisce un oggetto IAnchorInfo che fornisce informazioni sull'ancoraggio, ad esempio la posizione di ancoraggio, relativamente all’annotazione specificata.

public:
 static System::Windows::Annotations::IAnchorInfo ^ GetAnchorInfo(System::Windows::Annotations::AnnotationService ^ service, System::Windows::Annotations::Annotation ^ annotation);
public static System.Windows.Annotations.IAnchorInfo GetAnchorInfo (System.Windows.Annotations.AnnotationService service, System.Windows.Annotations.Annotation annotation);
static member GetAnchorInfo : System.Windows.Annotations.AnnotationService * System.Windows.Annotations.Annotation -> System.Windows.Annotations.IAnchorInfo
Public Shared Function GetAnchorInfo (service As AnnotationService, annotation As Annotation) As IAnchorInfo

Parametri

service
AnnotationService

Il servizio di annotazione da utilizzare per questa operazione.

annotation
Annotation

Annotazione per la quale ottenere informazioni sull’ancoraggio.

Restituisce

IAnchorInfo

Oggetto IAnchorInfo che fornisce informazioni sull’ancoraggio relativamente all’annotazione specificata o null se non può essere risolta.

Esempio

Prendere in considerazione un'applicazione di lettura documenti semplice con un riquadro commenti. Il riquadro dei commenti potrebbe essere una casella di riepilogo in cui viene visualizzato il testo di un elenco di annotazioni ancorate a un documento. Se l'utente seleziona un elemento della casella di riepilogo, nell'applicazione viene visualizzato il paragrafo del documento a cui è ancorato l'oggetto di annotazione corrispondente.

L'esempio seguente dimostra come implementare il gestore eventi di una casella di riepilogo di questo tipo che funge da riquadro dei commenti.

void annotationsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

    Annotation comment = (sender as ListBox).SelectedItem as Annotation;
    if (comment != null)
    {
        // IAnchorInfo info;
        // service is an AnnotationService object
        // comment is an Annotation object
        info = AnnotationHelper.GetAnchorInfo(this.service, comment);
        TextAnchor resolvedAnchor = info.ResolvedAnchor as TextAnchor;
        TextPointer textPointer = (TextPointer)resolvedAnchor.BoundingStart;
        textPointer.Paragraph.BringIntoView();
    }
}
Private Sub annotationsListBox_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)

    Dim comment As Annotation = TryCast((TryCast(sender, ListBox)).SelectedItem, Annotation)
    If comment IsNot Nothing Then
        ' service is an AnnotationService object
        ' comment is an Annotation object
        info = AnnotationHelper.GetAnchorInfo(Me.service, comment)
        Dim resolvedAnchor As TextAnchor = TryCast(info.ResolvedAnchor, TextAnchor)
        Dim textPointer As TextPointer = CType(resolvedAnchor.BoundingStart, TextPointer)
        textPointer.Paragraph.BringIntoView()
    End If
End Sub

Si applica a

Vedi anche