Question about annotation selection/deselection in SfChart
I'm adding a bunch of code to be able to attach annotations to an SfChart showing candlesticks on a DateTimeCategory axis. I have lots of it working just fine but hit a snag.
Basically, it should work like this -
The user selects the candlestick to annotate. That works fine. Clicking a candlestick opens a modal annotation form, and the annotation is added properly to that display x index.
I'd like the user to be able to drag the annotation to some vertical position above or below the candlestick, and save the new position. That works fine.
The user needs to be able to select the annotation by clicking on it, and thus open a modal form (MVVM) to edit the notes for that annotation. Here's where the problem crops up. I can select the annotation and get an event. No problem. What ISN'T obvious is how to deselect the annotation programmatically. Or to see which annotation(s) are selected. It's not like other group selection things in SF where you have a "SelectedItems" list I can clear or a "SelectedItem" to nullify in order to deselect the currently selected item. There also doesn't appear to be an IsSelected I can call and get at it that way.
This cropped up when I was trying to distinguish between a drag and a selection. I decided that since a lot of other stuff in the program "drags" if you hold down left-alt, I would just have the annotation selection event ignore the selection if the left-alt key was down. But there doesn't seem to be a way to know if, or which annotations are selected, or to clear the selection. And the selection seems to be persistent, in that if I select an annotation, it stays selected until i click another element, then I'll get the UnSelected event for that annotation.
Ideally, If the user has the left-alt key down, the annotation selection event should ignore the selection and not open the modal window for editing. The drag should then be permitted. When the left-alt key is released, the annotation selection should be programmatically cleared. And I can do all that, except deselecting the currently selected annotation. Since I CAN'T deselect the annotation programmatically, it stays selected. So, if I drag an annotation, then click it to edit the note, it doesn't issue another selected event.
I've looked it over for some time and I can't find a way to deselect an annotation from c#. Any suggestions?
Hi Thomas,
Thank you for reaching out to us.
Before we proceed further, we would like to clarify a few details to better understand your scenario and provide an accurate solution.
- Could you please confirm which annotation type you are using in the chart?
- Additionally, are you using the built-in drag functionality by enabling the CanDrag property, or have you implemented a custom drag behavior?
We would like to confirm the exact behavior you are experiencing and ensure it aligns with our understanding.
In our testing, we validated the scenario using a Rectangle Annotation with both Selected and Unselected events. When the rectangle annotation is clicked, the Selected event is triggered, and the annotation can be dragged and repositioned as expected. The annotation remains in the selected state until another chart element is clicked, at which point the Unselected event is raised. This behavior appears to be working as designed based on our validation.
Could you please confirm whether this is the same behavior you are observing on your end, or if you are experiencing any different or unexpected behavior? If there are any deviations from the above, kindly share the details or demo that reproduces the issue so that we can investigate further and provide a precise solution.
If you have any further questions, please feel free to let us know. We will be happy to assist you.
Regards,
Vallarasu R
Hi, Vallerasu -
It's the stock drag behavior on an ellipse annotation.
My issue is that I need to be able to deselect the annotation programmatically. This is because once it's selected, you won't get another Selected event if the annotation is clicked for editing.
In this case, if the annotation is dragged, the user can't then select it for editing without deselecting it first by clicking off to one side. This "feels" like the selection is erratic to the end-user, who will expect it to deselect at the end of the drag.
I had intended to programmatically deselect the annotation on DragCompleted or upon exiting the editing form, but there doesn't appear to be a way to do this.
Thomas
Hi Thomas,
Thank you for your detailed explanation.
The Selected event is raised only when an annotation is selected for the first time. The UnSelected event is triggered when focus moves to another chart element. This is the current and expected behavior of the WPF SfChart annotation selection mechanism.
For your requirement, although annotations cannot be truly deselected programmatically, you can handle your interaction logic within the available annotation events such as DragCompleted, Selected, or UnSelected to achieve the desired user experience.
<syncfusion:EllipseAnnotation ... UnSelected="EllipseAnnotation_UnSelected" DragCompleted="EllipseAnnotation_DragCompleted"/> |
private void EllipseAnnotation_UnSelected(object sender, EventArgs e) { // Handle your post-unselection requirements here
private void EllipseAnnotation_DragCompleted(object sender, AnnotationDragCompletedEventArgs e) { EllipseAnnotation_UnSelected(sender, EventArgs.Empty); } |
You can further customize this behavior using other annotation interaction-related events based on your application needs.
For more details, please refer to the documentation:
Annotations in WPF Charts control | Syncfusion.
Please let us know if you need any additional assistance, or if the provided suggestion does not align with your requirement.
Regards,
Vimala.
- 3 Replies
- 3 Participants
-
TB Thomas Brand
- Mar 31, 2026 08:04 PM UTC
- Apr 2, 2026 12:41 PM UTC