how to use RadSpellChecker in mvvm

2 posts, 0 answers
  1. Jerry
    Jerry avatar
    10 posts
    Member since:
    Mar 2013

    Posted 04 Sep 2013 Link to this post

    I am trying to add RadSpellChecker to our SilverLight application which is using MVVM.

    I have added these assemblies to the project: Telerik.Windows.Documents.Proofing,Telerik.Windows.Documents.Proofing.En-US

    The textbox "Text" property on my View is bound to Text="{Binding Model.Description}"
    The Button "Command" is Command="{Binding Model.SpellcheckCommand}"

    In my ViewModel I have added these namespaces
    using Telerik.Windows.Documents;
    using Telerik.Windows.Controls;

    In the SpellChecker method in the ViewModel I have the following but the RadSpellChecker says I'm missing an assembly reference.
            public void SpellCheck()
                Telerik.Windows.Controls.RadSpellChecker.Check(Model.Description, SpellCheckingMode.WordByWord);

    Do I have to call RadSpellChecker from the View's code behind instead?
  2. Petya
    Petya avatar
    990 posts

    Posted 06 Sep 2013 Link to this post

    Hello Jerry,

    From your explanation it seems you are trying to pass the string property to which the TextBox is bound to the spellchecker, is that correct? RadSpellChecker's Check() method requires a Control instance to be passed as parameter. That said, I'd suggest you pass the TextBox from your view as a command parameter.

    Additionally, in some cases MEF is unable to load the needed spellchecker. To resolve the problem you can register the spellcheckers for TextBox before the RadSpellChecker.Check() call like this:
    ControlSpellCheckersManager.RegisterControlSpellChecker(new TextBoxSpellChecker());
    IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(TextBox));
    ISpellChecker spellChecker = controlSpellchecker.SpellChecker;
    DocumentSpellChecker documentSpellChecker = (DocumentSpellChecker)spellChecker;
    documentSpellChecker.AddDictionary(new RadEn_USDictionary(), new System.Globalization.CultureInfo("en-US"));

    I hope this helps!

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top