Skip to main content

ChartControl.AnnotationRepositoryChanging Event

Occurs when a user adds, edits or deletes an annotation before the user’s operation is applied to the annotation repository.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v23.2.UI.dll

NuGet Package: DevExpress.Win.Charts

Declaration

public event AnnotationRepositoryChangingEventHandler AnnotationRepositoryChanging

Event Data

The AnnotationRepositoryChanging event's data class is AnnotationRepositoryChangingEventArgs. The following properties provide information specific to this event:

Property Description
Annotation Returns the annotation that is being changed.
Cancel Indicates whether to cancel the annotation change.
Change Returns the AnnotationRepositoryChange value that indicates the type of change a user makes.

Remarks

Users can utilize the Add Text Annotation and Add Image Annotation buttons in the Chart’s Ribbon or Toolbars to add interactive annotations. They can also edit or delete an annotation if the Annotation.RuntimeEditing property is set to true.

The e.Change property returns an operation that a user performs. The Change property can be set to the following values:

The e.Annotation property returns the changed annotation. The e.Cancel property indicates whether to cancel the last change.

The following example prevents Annotation1 from being deleted.

void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Annotation.Name == "Annotation1" && e.Change == AnnotationRepositoryChange.Deletion) {
        e.Cancel = true;
    }
}

When a user edits an image annotation, use AnnotationImageEditingEventArgs to get a file path to the new annotation image. Cast AnnotationRepositoryChangingEventArgs to the AnnotationImageEditingEventArgs type and use the AnnotationImageEditingEventArgs.NewImageFileName property for this purpose:

 void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Change == AnnotationRepositoryChange.Image) {
    AnnotationImageEditingEventArgs imageEditingArgs = (AnnotationImageEditingEventArgs)e;
    string imageFile = imageEditingArgs.NewImageFileName;
    //Add your logic here. 
    }
 }    

When a user edits a text annotation, use the AnnotationTextEditingEventArgs to get new annotation text. Cast the AnnotationRepositoryChangingEventArgs to the AnnotationTextEditingEventArgs type. The AnnotationTextEditingEventArgs.NewText property returns new text as shown in the following example:

void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Change == AnnotationRepositoryChange.Text) {
    AnnotationTextEditingEventArgs textEditingArgs = (AnnotationTextEditingEventArgs)e;
    string newAnnotationText = textEditingArgs.NewText;
    //Add your logic here. 
    }    
}
See Also