wpf-devexpress-dot-xpf-dot-pdfviewer-dot-pdfviewercontrol-01b54036.md
Fires before the annotation is created.
Namespace : DevExpress.Xpf.PdfViewer
Assembly : DevExpress.Xpf.PdfViewer.v25.2.dll
NuGet Package : DevExpress.Wpf.PdfViewer
public event PdfAnnotationCreatingEventHandler AnnotationCreating
Public Event AnnotationCreating As PdfAnnotationCreatingEventHandler
The AnnotationCreating event's data class is PdfAnnotationCreatingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Builder | Gets the object used to build an annotation. |
| Cancel | Gets or sets whether the event should be canceled. |
| Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
| OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
| RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
| Source | Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
| OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
The AnnotationCreating event fires when the user creates an annotation from the User Interface or after one of the following methods are called:
| Method | Description |
|---|---|
| PdfViewerControl.HighlightSelectedText | Highlights the selected text. |
| PdfViewerControl.StrikethroughSelectedText | Strikes through the selected text. |
| PdfViewerControl.UnderlineSelectedText | Underlines the selected text. |
| PdfViewerControl.AddStickyNote | Adds a sticky note at the specified position. |
The PdfAnnotationCreatingEventArgs.Builder property retrieves the annotation parameters. Use the DevExpress.Pdf.PdfViewerAnnotationBuilderExtensions class methods to obtain a specific type of annotation.
The following code shows how to handle the PdfViewerControl.AnnotationCreating event:
using DevExpress.Pdf;
using DevExpress.Xpf.DocumentViewer;
using DevExpress.Xpf.PdfViewer;
using System.Windows;
namespace MarkupAnnotations
{
public partial class MainWindow : DevExpress.Xpf.Core.ThemedWindow
{
public MainWindow()
{
InitializeComponent();
// Load a document.
viewer.OpenDocument("..\\..\\Demo.pdf");
viewer.AnnotationCreating += Viewer_TextMarkupAnnotationCreating;
}
private void Viewer_TextMarkupAnnotationCreating
(DependencyObject d, PdfAnnotationCreatingEventArgs e)
{
if (e.Builder.AnnotationType == PdfAnnotationType.Text
|| e.Builder.AnnotationType == PdfAnnotationType.TextMarkup)
{
IPdfViewerMarkupAnnotationBuilder annotationBuilder =
e.Builder.AsMarkupAnnotationBuilder();
annotationBuilder.Author = "John Smith";
annotationBuilder.Contents = "Note";
annotationBuilder.Color = new PdfRGBColor(0.23, 0.48, 0.34);
}
}
private void viewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
// Select the text to highlight:
viewer.FindText
(new TextSearchParameter { Text = "PDF Viewer" });
// Highlight selected text:
viewer.HighlightSelectedText();
//Add a sticky note:
viewer.AddStickyNote
(new PdfDocumentPosition(1, new PdfPoint(29, 568)), "Comment");
}
}
}
Imports DevExpress.Pdf
Imports DevExpress.Xpf.DocumentViewer
Imports DevExpress.Xpf.PdfViewer
Imports System.Windows
Namespace MarkupAnnotations
Partial Public Class MainWindow
Inherits DevExpress.Xpf.Core.ThemedWindow
Public Sub New()
InitializeComponent()
' Load a document.
viewer.OpenDocument("..\..\Demo.pdf")
AddHandler viewer.AnnotationCreating, AddressOf Viewer_TextMarkupAnnotationCreating
End Sub
Private Sub Viewer_TextMarkupAnnotationCreating
(ByVal d As DependencyObject, ByVal e As PdfAnnotationCreatingEventArgs)
If e.Builder.AnnotationType = PdfAnnotationType.Text
OrElse e.Builder.AnnotationType = PdfAnnotationType.TextMarkup Then
Dim annotationBuilder As IPdfViewerMarkupAnnotationBuilder =
e.Builder.AsMarkupAnnotationBuilder()
annotationBuilder.Author = "John Smith"
annotationBuilder.Contents = "Note"
annotationBuilder.Color = New PdfRGBColor(0.23, 0.48, 0.34)
End If
End Sub
Private Sub viewer_DocumentLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Select the text to highlight:
viewer.FindText
(New TextSearchParameter With {.Text = "PDF Viewer"})
' Highlight selected text:
viewer.HighlightSelectedText()
'Add a sticky note:
viewer.AddStickyNote
(New PdfDocumentPosition(1, New PdfPoint(29, 568)), "Comment")
End Sub
End Class
End Namespace
See Also