This documentation is archived and is not being maintained.

AnnotationHelper.CreateHighlightForSelection Method

Creates a highlight annotation on the current selection of the viewer control associated with the specified AnnotationService.

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

public static Annotation CreateHighlightForSelection(
	AnnotationService service,
	string author,
	Brush highlightBrush
You cannot use methods in XAML.


Type: System.Windows.Annotations.AnnotationService

The annotation service to use to create the highlight annotation.

Type: System.String

The author of the annotation.

Type: System.Windows.Media.Brush

The brush to use to draw the highlight over the selected content.

Return Value

Type: System.Windows.Annotations.Annotation
The highlight annotation; or null, if there is no selected content to highlight.


service is null.


service is not enabled.


highlightBrush in not a SolidColorBrush.


The viewer control contains no content selection.

The highlight annotation is anchored to the content defined by the current selection of the DocumentViewerBase, DocumentViewer, FlowDocumentPageViewer, FlowDocumentScrollViewer, or FlowDocumentReader control specified to the AnnotationService constructor.

If there is no selected content (the selection length is zero length), no annotation is created and an InvalidOperationException is thrown.

author can be specified as null in which case no author is defined.

If highlightBrush is null, the default highlight brush of the given annotation service is used.

The given annotation service must be enabled by means of a call to AnnotationService.Enable prior to calling CreateHighlightForSelection.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0