Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/annotations-overview.md
T
David CoulterandAndy De George 674b773578 Links: .NET Desktop - framework\wpf (#109)
* Links: .NET Desktop - framework\wpf

* Apply suggestions from code review

Co-authored-by: Andy De George <[email protected]>
2020-11-05 13:50:29 -08:00

6.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Annotations Overview 03/30/2017
csharp
vb
highlights [WPF]
documents [WPF], annotations
sticky notes [WPF]
716bf474-29bd-4c74-84a4-8e0744bdad62

Annotations Overview

Writing notes or comments on paper documents is such a commonplace activity that we almost take it for granted. These notes or comments are "annotations" that we add to a document to flag information or to highlight items of interest for later reference. Although writing notes on printed documents is easy and commonplace, the ability to add personal comments to electronic documents is typically very limited, if available at all.

This topic reviews several common types of annotations, specifically sticky notes and highlights, and illustrates how the Microsoft Annotations Framework facilitates these types of annotations in applications through the Windows Presentation Foundation (WPF) document viewing controls. WPF document viewing controls that support annotations include xref:System.Windows.Controls.FlowDocumentReader and xref:System.Windows.Controls.FlowDocumentScrollViewer, as well as controls derived from xref:System.Windows.Controls.Primitives.DocumentViewerBase such as xref:System.Windows.Controls.DocumentViewer and xref:System.Windows.Controls.FlowDocumentPageViewer.

Sticky Notes

A typical sticky note contains information written on a small piece of colored paper that is then "stuck" to a document. Digital sticky notes provide similar functionality for electronic documents, but with the added flexibility to include many other types of content such as typed text, handwritten notes (for example, Tablet PC "ink" strokes), or Web links.

The following illustration shows some examples of highlight, text sticky note, and ink sticky note annotations.

Highlight, text and ink sticky note annotations.

The following example shows the method that you can use to enable annotation support in your application.

[!code-csharpDocViewerAnnotationsXml#DocViewXmlStartAnnotations] [!code-vbDocViewerAnnotationsXml#DocViewXmlStartAnnotations]

Highlights

People use creative methods to draw attention to items of interest when they mark up a paper document, such as underlining, highlighting, circling words in a sentence, or drawing marks or notations in the margin. Highlight annotations in Microsoft Annotations Framework provide a similar feature for marking up information displayed in WPF document viewing controls.

The following illustration shows an example of a highlight annotation.

Highlight Annotation

Users typically create annotations by first selecting some text or an item of interest, and then right-clicking to display a xref:System.Windows.Controls.ContextMenu of annotation options. The following example shows the [!INCLUDETLA#tla_xaml] you can use to declare a xref:System.Windows.Controls.ContextMenu with routed commands that users can access to create and manage annotations.

[!code-xamlDocViewerAnnotationsXps#CreateDeleteAnnotations]

Data Anchoring

The Annotations Framework binds annotations to the data that the user selects, not just to a position on the display view. Therefore, if the document view changes, such as when the user scrolls or resizes the display window, the annotation stays with the data selection to which it is bound. For example, the following graphic illustrates an annotation that the user has made on a text selection. When the document view changes (scrolls, resizes, scales, or otherwise moves), the highlight annotation moves with the original data selection.

Annotation Data Anchoring

Matching Annotations with Annotated Objects

You can match annotations with the corresponding annotated objects. For example, consider a simple document reader application that has a comments pane. The comments pane might be a list box that displays the text from a list of annotations that are anchored to a document. If the user selects an item in the list box, then the application brings into view the paragraph in the document that the corresponding annotation object is anchored to.

The following example demonstrates how to implement the event handler of such a list box that serves as the comments pane.

[!code-csharpFlowDocumentAnnotatedViewer#Handler] [!code-vbFlowDocumentAnnotatedViewer#Handler]

Another example scenario involves applications that enable the exchange of annotations and sticky notes between document readers through email. This feature enables these applications to navigate the reader to the page that contains the annotation that is being exchanged.

See also