語言

AnnotationHelper.GetAnchorInfo(AnnotationService, Annotation) 方法

定義

回傳 IAnchorInfo 一個物件,提供關於指定註解的錨定資訊,例如錨點位置。

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

參數

service
AnnotationService

用於此操作的註解服務。

annotation
Annotation

標註用來取得錨定資訊。

傳回

一個 IAnchorInfo 提供指定註解錨定資訊的物件,或 null 在無法解析時提供該標註。

範例

考慮一個簡單的文件閱讀器應用程式,帶有註解窗格。 註解窗格可能是清單方塊,顯示錨定到文件的註解清單中的文字。 如果使用者在清單方塊中選取項目,則應用程式會將對應註釋物件所錨定之文件中的段落帶入檢視。

下列範例示範如何為這類作為註解窗格的清單方塊實作事件處理常式。

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

適用於

另請參閱