Pre loader

Why does the Text property for a TextAnnotation not reflect the current text until the focus is moved?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
1
0

We’re allowing our users to place down annotations on the chart with an annotation creation modifier. One of these annotations is a Text annotation.

We then allow users to save these annotations into our own proprietary file format and load them back in with the chart data. To do this we iterate through the AnnotationCollection of the chart and parse the SciChart annotations to data we save to our files.

To save the content of the text for the TextAnnotation we read the TextAnnotation.Text property. However, we’ve noticed that this property is not set until the annotation has lost focus (we click away from the annotation somewhere else on the chart). If we save the annotation before we click away from it, we do not get the current text from the TextAnnotation.Text property.

The process to reproduce this is:
1. Place down a TextAnnotation.
2. Edit the TextAnnotation content. Do not click away from the text so to annotation remains in “Editing” mode
3. Save the data.
4. As we’re saving we read the TextAnnotation.Text property to save to our file. However, the TextAnnotation.Text property returns a blank string because its still being edited.

Is there a way from within our code that we can finish the editing of the text annotation, so that when we get the TextAnnotation.Text property it is the current text the user typed in? Or is there a way to get the current text within the TextAnnotation without finishing the editing or changing the focus?

Version
7.0.2.27161
  • You must to post comments
Best Answer
1
1

Hi Jamie,

Thanks for your inquiry.
This is the default behavior of WPF TextBox, which is used under the hood of our TextAnnotation.

We would suggest you try forcing Focus to any other control before saving the data. This can be done using WPF capabilities, for instance, FocusManager:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.setfocusedelement?view=windowsdesktop-8.0

Alternatively, you can override the TextAnnotation Template to update it on a keypress:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-control-when-the-textbox-text-updates-the-source?view=netframeworkdesktop-4.8

Please let us know if you are interested in this option. We can share the default Template.

Kind regards,
Lex S., MSEE
SciChart Technical Support Engineer

  • You must to post comments
1
0

The FocusManager approach worked perfectly. Thank you.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.