AnnotationHelper.GetAnchorInfo(AnnotationService, Annotation) Método

Definición

Devuelve un IAnchorInfo objeto que proporciona información de delimitación, como la ubicación del anclaje, sobre la anotación especificada.

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

Parámetros

service
AnnotationService

Servicio de anotación que se va a usar para esta operación.

annotation
Annotation

Anotación para la que se obtiene información de delimitación.

Devoluciones

Objeto IAnchorInfo que proporciona información de delimitación sobre la anotación especificada o null si no se puede resolver.

Ejemplos

Considere una aplicación de lector de documentos sencilla que tenga un panel de comentarios. El panel de comentarios puede ser un cuadro de lista que muestra el texto de una lista de anotaciones que están ancladas a un documento. Si el usuario selecciona un elemento en el cuadro de lista, la aplicación muestra el párrafo del documento al que está anclado el objeto de anotación correspondiente.

En el ejemplo siguiente se muestra cómo implementar el controlador de eventos de este tipo de cuadro de lista que actúa como panel de comentarios.

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

Se aplica a

Consulte también