This is a migrated thread and some comments may be shown as answers.

Creating Outlook-like spellchecking capability

6 Answers 121 Views
SpellChecker
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 2
Bruce asked on 26 Dec 2017, 07:00 PM
I was wondering if anyone has any sample code that shows how to properly invoke RadSpellChecker (without using codebehind, but proper MVVM methodology) on a TextBox when a user is submits a form for persistence. Also, if the user dismisses the spell checker while there are still misspelled words, a notification alert box should pop-up allowing the user to either continue (with "misspellings" not corrected) or cancel and allow the submit action to cancel itself. I don't see how RadSpellChecker allows for the ability to determine if the user has left behind any non-corrected words. My guess is that the DocumentSpellChecker must somehow be put to use, but I'm hoping to minimize complexity. Thanks for any assistance in advance.

6 Answers, 1 is accepted

Sort by
0
Bruce
Top achievements
Rank 2
answered on 26 Dec 2017, 09:15 PM
I just discovered that the one event off of the RadSpellChecker has the ability to detect if the user canceled the operation [...now I wish this forum allowed me to edit my own post]. However, I'm still wondering what's a best practice way to bring up the spell checker on a text box when a user hits a submit button on a form and then examine the results of the user's interaction before allowing the submit to continue.
0
Bruce
Top achievements
Rank 2
answered on 27 Dec 2017, 08:09 PM
...and, one additional thing I noticed. I guess it's not possible for the spell checker dialog to automatically dismiss itself once the user has completed any corrections so they don't have to hit the "OK" button when done?
0
Tanya
Telerik team
answered on 28 Dec 2017, 02:38 PM
Hello Bruce,

Depending on the implementation of the Submit functionality, you could create a command that invokes the desired functionality of RadSpellChecker. The control itself, however, cannot be directly invoked through XAML. When the users submit the form, you could use the AllAtOnce spellchecking mode and verify that the text is correct. In case there are still errors, you can show a popup and one of the spell check dialogs (using the Check() method) to the user so they can correct what is left. The actions of the user are not stored anywhere, though, and you can detect only if the spell checking has been canceled using the arguments of the SpellCheckingCompleted event of RadSpellChecker or if a word has been added or removed from the dictionary in use using the DataChanged event of DocumentSpellChecker
IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(TextBox));
DocumentSpellChecker documentSpellChecker = (DocumentSpellChecker) controlSpellchecker.SpellChecker;
documentSpellChecker.DataChanged += DocumentSpellChecker_DataChanged;

You are right that the OK button cannot be dismissed. I created a public item which you can use to vote for extending the functionalities of RadSpellChecker. One of the improvements logged there is to allow loading custom dialogs for the control, which would allow you to customize the behavior of the dialog as well. 

Hope this information is helpful.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Bruce
Top achievements
Rank 2
answered on 28 Dec 2017, 05:00 PM

Tanya, I appreciate your prompt response! Just a couple of follow-up questions.

1 - Could you please request a modest enhancement to the RadSpellChecker control that adds a property to have it auto-dismiss once the user has gone through all the corrections (without cancelling it first)? This would seem to be a simple enhancement versus having the developer to customize a dialog box. However, I think allowing the dialog to be customized is still a good idea for more complex functionality.

2 - Since the Check() method takes a Content control as a parameter, I'm not sure it's a good idea for the view model to take in a control from the view. By any chance, do you have a sample of a behavior (such as one that might be on the Submit button or perhaps a property that sets up an event on the control to be checked) that might already put this functionality in place?

Thank you again!

 

0
Accepted
Boby
Telerik team
answered on 29 Dec 2017, 02:22 PM
Hello Bruce,

After further review of your scenario and discussions within the team, we came to the conclusion that your requirement for skipping the "The spelling check is complete" state of the dialog is already logged as a bug report here:
SpellChecker: RadSpellChecker.WindowSettings.ShowAlertWhenSpellCheckingCompleted doesn't suppress all alerts in AllAtOnce scenario
The item contains a workaround, which completely replaces the default TextBox spell checker with custom one, showing the "fixed" dialog.

For the MVVM approach - we do not have such behavior implemented, but I think one possible approach would be to implement your custom attached property. When set to a specific TextBox (in XAML), it could register it in a special collection; then when the Submit command for your form is executed, it could execute the spell checking on all controls in the collection - it's not the cleanest approach, but there won't be a direct reference between the ViewModel and the View.

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Bruce
Top achievements
Rank 2
answered on 29 Dec 2017, 03:55 PM

Boby, I'll definitely check out that link.

By the way, you guys are awesome with your support on these forums. You've definitely gone beyond my expectations!

 

With much appreciation,

Bruce

Tags
SpellChecker
Asked by
Bruce
Top achievements
Rank 2
Answers by
Bruce
Top achievements
Rank 2
Tanya
Telerik team
Boby
Telerik team
Share this question
or