AnnotationHelper.GetAnchorInfo(AnnotationService, Annotation) Metodo

Definizione

Restituisce un IAnchorInfo oggetto che fornisce informazioni di ancoraggio, ad esempio la posizione di ancoraggio, sull'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

Servizio di annotazione da utilizzare per questa operazione.

annotation
Annotation

Annotazione per cui ottenere informazioni di ancoraggio.

Valori restituiti

Oggetto IAnchorInfo che fornisce informazioni di ancoraggio sull'annotazione specificata o null se non può essere risolto.

Esempio

Si consideri un'applicazione lettore di documenti semplice con un riquadro commenti. Il riquadro dei commenti potrebbe essere una casella di riepilogo che visualizza il testo di un elenco di annotazioni ancorate a un documento. Se l'utente seleziona un elemento nella casella di riepilogo, l'applicazione visualizza il paragrafo del documento a cui è ancorato l'oggetto annotazione corrispondente.

Nell'esempio seguente viene illustrato 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