Creating Outlook-like spellchecking capability

7 posts, 1 answers
  1. Bruce
    Bruce avatar
    6 posts
    Member since:
    Nov 2015

    Posted 26 Dec 2017 Link to this post

    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.
  2. Bruce
    Bruce avatar
    6 posts
    Member since:
    Nov 2015

    Posted 26 Dec 2017 in reply to Bruce Link to this post

    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.
  3. Bruce
    Bruce avatar
    6 posts
    Member since:
    Nov 2015

    Posted 27 Dec 2017 Link to this post

    ...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?
  4. Tanya
    Admin
    Tanya avatar
    718 posts

    Posted 28 Dec 2017 Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Bruce
    Bruce avatar
    6 posts
    Member since:
    Nov 2015

    Posted 28 Dec 2017 in reply to Tanya Link to this post

    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!

     

  6. Answer
    Boby
    Admin
    Boby avatar
    684 posts

    Posted 29 Dec 2017 Link to this post

    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.
  7. Bruce
    Bruce avatar
    6 posts
    Member since:
    Nov 2015

    Posted 29 Dec 2017 in reply to Boby Link to this post

    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

Back to Top