AnnotationHelper.GetAnchorInfo(AnnotationService, Annotation) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne un IAnchorInfo objet qui fournit des informations d’ancrage, telles que l’emplacement d’ancrage, sur l’annotation spécifiée.
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
Paramètres
- service
- AnnotationService
Service d’annotation à utiliser pour cette opération.
- annotation
- Annotation
Annotation pour laquelle obtenir des informations d’ancrage.
Retours
Objet IAnchorInfo qui fournit des informations d’ancrage sur l’annotation spécifiée ou null s’il ne peut pas être résolu.
Exemples
Considérez une application de lecteur de document simple qui a un volet commentaires. Le volet commentaires peut être une zone de liste qui affiche le texte d’une liste d’annotations ancrées dans un document. Si l’utilisateur sélectionne un élément dans la zone de liste, l’application affiche le paragraphe du document auquel l’objet d’annotation correspondant est ancré.
L’exemple suivant montre comment implémenter le gestionnaire d’événements d’une telle zone de liste qui sert de volet commentaires.
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