Events in WPF Diagram (SfDiagram)
29 Nov 20241 minute to read
Annotation Changed Event
The AnnotationChanged event will notify the annotation related actions and value changes. The AnnotationChangedEventArgs class is used to get or set the entire annotation related properties and their values.
//Register the AnnotationChanged event
(diagram.Info as IGraphInfo).AnnotationChanged += Diagram_AnnotationChanged;
//Method to show message box when annotation is changed
private void Diagram_AnnotationChanged(object sender, ChangeEventArgs<object, AnnotationChangedEventArgs> args)
{
//When annotation is resized
if (args.NewValue.AnnotationInteractionState == AnnotationInteractionState.Resized)
{
MessageBox.Show("Annotation has been resized!");
}
//When annotation is resized
if (args.NewValue.AnnotationInteractionState == AnnotationInteractionState.Rotated)
{
MessageBox.Show("Annotation has been rotated!");
}
//When annotation is resized
if (args.NewValue.AnnotationInteractionState == AnnotationInteractionState.Edited)
{
MessageBox.Show("Annotation has been edited!");
}
}
Selection Events:
-
The ItemSelectingEvent and ItemSelectedEvent notify when an annotation is selected. The event arguments, derived from DiagramPreviewEventArgs and DiagramEventArgs, provide the selected item, which can be an
AnnotationEditorViewModel
orTextAnnotationViewModel
, depending on the annotation type. -
The ItemUnSelectingEvent and ItemUnSelectedEvent notify when an annotation is unselected. The event arguments, also derived from DiagramPreviewEventArgs and DiagramEventArgs, provide the unselected item, which can be an
AnnotationEditorViewModel
orTextAnnotationViewModel
, based on the annotation type.
See Also
How to add or remove annotation constraints?
How to localize the annotations?
How to restrict annotation editing by double-clicking the node or connector?