AnnotationService Constructor (DocumentViewerBase)


Initializes a new instance of the AnnotationService class for use with a specified DocumentViewer or FlowDocumentPageViewer control.

Namespace:   System.Windows.Annotations
Assembly:  PresentationFramework (in PresentationFramework.dll)

public AnnotationService(
	DocumentViewerBase viewer


Type: System.Windows.Controls.Primitives.DocumentViewerBase

The document viewing control associated with the AnnotationService.

Exception Condition

viewer is null.

This constructor can be used with DocumentViewerBase derived controls:

The following example shows use of the AnnotationService constructor.

// ------------------------ 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)

    // 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.
}// end:StartAnnotations()

.NET Framework
Available since 3.0
Return to top