紙文書にメモやコメントを書くことは、当たり前のように当たり前の活動です。 これらのメモまたはコメントは、情報にフラグを設定したり、後で参照できるように関心のある項目を強調表示したりするためにドキュメントに追加する "注釈" です。 印刷された文書にメモを書くことは簡単で一般的ですが、電子文書に個人的なコメントを追加する機能は、通常、まったく利用可能であれば非常に限られています。
このトピックでは、いくつかの一般的な種類の注釈(特に付箋とハイライト)を確認し、Microsoft Annotations Framework が Windows Presentation Foundation (WPF) ドキュメント表示コントロールを使用してアプリケーションでこれらの種類の注釈を容易にする方法について説明します。 注釈をサポートする WPF ドキュメント表示コントロールには、FlowDocumentReader と FlowDocumentScrollViewerのほか、DocumentViewerBase や DocumentViewerなどの FlowDocumentPageViewer から派生したコントロールが含まれます。
付箋
一般的な付箋には、小さな色付きの紙に書かれた情報が含まれ、文書に "貼り付け" されます。 デジタル付箋は電子ドキュメントにも同様の機能を提供しますが、入力されたテキスト、手書きのノート (タブレット PC の "インク" ストロークなど)、Web リンクなど、他の多くの種類のコンテンツを含める柔軟性が追加されています。
次の図は、強調表示、テキスト付箋、インク付箋注釈の例をいくつか示しています。
次の例は、アプリケーションで注釈のサポートを有効にするために使用できるメソッドを示しています。
// ------------------------ StartAnnotations --------------------------
/// <summary>
/// Enables annotations and displays all that are viewable.</summary>
private void StartAnnotations()
{
// If there is no AnnotationService yet, create one.
if (_annotService == null)
// docViewer is a document viewing control named in Window1.xaml.
_annotService = new AnnotationService(docViewer);
// If the AnnotationService is currently enabled, disable it.
if (_annotService.IsEnabled == true)
_annotService.Disable();
// Open a stream to the file for storing annotations.
_annotStream = new FileStream(
_annotStorePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
// Create an AnnotationStore using the file stream.
_annotStore = new XmlStreamStore(_annotStream);
// Enable the AnnotationService using the new store.
_annotService.Enable(_annotStore);
}// end:StartAnnotations()
' ------------------------ StartAnnotations --------------------------
''' <summary>
''' Enables annotations and displays all that are viewable.</summary>
Private Sub StartAnnotations()
' If there is no AnnotationService yet, create one.
If _annotService Is Nothing Then
' docViewer is a document viewing control named in Window1.xaml.
_annotService = New AnnotationService(docViewer)
End If
' If the AnnotationService is currently enabled, disable it.
If _annotService.IsEnabled = True Then
_annotService.Disable()
End If
' Open a stream to the file for storing annotations.
_annotStream = New FileStream(_annotStorePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
' Create an AnnotationStore using the file stream.
_annotStore = New XmlStreamStore(_annotStream)
' Enable the AnnotationService using the new store.
_annotService.Enable(_annotStore)
End Sub
概要
ユーザーは、文書の下線付け、強調表示、文内の単語の囲み、余白の記号や表記など、紙の文書を作成するときに、クリエイティブな方法を使用して関心のあるアイテムに注意を引きます。 Microsoft Annotations Framework の強調表示注釈は、WPF ドキュメント表示コントロールに表示される情報をマークアップするための同様の機能を提供します。
次の図は、強調表示注釈の例を示しています。
ユーザーは通常、最初にテキストまたは関心のある項目を選択し、右クリックして注釈オプションの ContextMenu を表示することで、注釈を作成します。 次の例は、ユーザーが注釈の作成と管理にアクセスできるルーティング コマンドを使用して ContextMenu を宣言するために使用できる拡張アプリケーション マークアップ言語 (XAML) を示しています。
<DocumentViewer.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Copy" />
<Separator />
<!-- Add a Highlight annotation to a user selection. -->
<MenuItem Command="ann:AnnotationService.CreateHighlightCommand"
Header="Add Highlight" />
<!-- Add a Text Note annotation to a user selection. -->
<MenuItem Command="ann:AnnotationService.CreateTextStickyNoteCommand"
Header="Add Text Note" />
<!-- Add an Ink Note annotation to a user selection. -->
<MenuItem Command="ann:AnnotationService.CreateInkStickyNoteCommand"
Header="Add Ink Note" />
<Separator />
<!-- Remove Highlights from a user selection. -->
<MenuItem Command="ann:AnnotationService.ClearHighlightsCommand"
Header="Remove Highlights" />
<!-- Remove Text Notes and Ink Notes from a user selection. -->
<MenuItem Command="ann:AnnotationService.DeleteStickyNotesCommand"
Header="Remove Notes" />
<!-- Remove Highlights, Text Notes, Ink Notes from a selection. -->
<MenuItem Command="ann:AnnotationService.DeleteAnnotationsCommand"
Header="Remove Highlights & Notes" />
</ContextMenu>
</DocumentViewer.ContextMenu>
データの固定
Annotations Framework は、表示ビュー上の位置だけでなく、ユーザーが選択したデータに注釈をバインドします。 したがって、ユーザーが表示ウィンドウをスクロールまたはサイズ変更したときなど、ドキュメント ビューが変更された場合、注釈はバインド先のデータ選択と共に保持されます。 たとえば、次の図は、ユーザーがテキスト選択に対して行った注釈を示しています。 ドキュメント ビューが変更されると (スクロール、サイズ変更、拡大縮小など)、強調表示注釈は元のデータ選択と共に移動します。
注釈と注釈付きオブジェクトの照合
注釈は、対応する注釈付きオブジェクトと照合できます。 たとえば、コメント ウィンドウがある単純なドキュメント リーダー アプリケーションを考えてみましょう。 コメント ウィンドウは、ドキュメントに固定されている注釈のリストのテキストを表示するリスト ボックスである場合があります。 ユーザーがリスト ボックスで項目を選択すると、アプリケーションは、対応する注釈オブジェクトが固定されているドキュメント内の段落を表示します。
次の例では、コメント ウィンドウとして機能するこのようなリスト ボックスのイベント ハンドラーを実装する方法を示します。
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
もう 1 つのシナリオ例には、ドキュメント リーダー間で電子メールを介して注釈と付箋を交換できるようにするアプリケーションが含まれます。 この機能により、これらのアプリケーションは、交換される注釈を含むページにリーダーを移動できます。
こちらも参照ください
.NET Desktop feedback