Dictionary not adding in MEF

5 posts, 0 answers
  1. Rav
    Rav avatar
    36 posts
    Member since:
    Nov 2011

    Posted 05 Jun 2011 Link to this post

    Hi Telerik,

    I have a Silverlight application using MEF. I am trying to get the new RadSpellChecker control to work on a TextBox that I have, located inside a UserControl that is loaded at runtime via MEF.

    In the main project I have added reference to the following:
    Telerik.Windows.Controls
    Telerik.Windows.Documents
    Telerik.Windows.Documents.Proofing
    Telerik.Windows.Documents.Proofing.Dictionaries.En-US

    Within the Application_Startup method I have created the following:
    ControlSpellCheckersManager.RegisterControlSpellChecker(new TextBoxSpellChecker());
    IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(TextBox));
    ISpellChecker spellChecker = controlSpellchecker.SpellChecker;
    ((DocumentSpellChecker)spellChecker).AddDictionary(new RadEn_USDictionary(), new System.Globalization.CultureInfo("en-US"));

    In the Silverlight project for the 'MEFed' UserControl I have references to the same assemblies and have the following code in a Click handler:
    RadSpellChecker.Check(this.WrittenBody, SpellCheckingMode.AllAtOnce);

    The RadSpellChecker window displays and the text is as typed in the TextBox, however the suggestions box is always empty.

    When I debug the application at the point of the Click handler, I can see the correct instance of the IControlSpellChecker, but the associated DictionaryList is empty.

    Any help would be appreciated.

    Rav
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 09 Jun 2011 Link to this post

    Hello Rav Panchalingam,

    The CheckAllAtOnce dialog actually makes use of the document spell checker for RadRichTextBox. Thus, you also need to register a RadRichTextBoxSpellChecker in order to make it work.
    Please, try the code from the snippet below and let us know how it goes:

    public MainPage()
    {
        InitializeComponent();
     
        ControlSpellCheckersManager.RegisterControlSpellChecker(new TextBoxSpellChecker());
     
        ControlSpellCheckersManager.RegisterControlSpellChecker(new RadRichTextBoxSpellChecker());
        IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(RadRichTextBox));
        ISpellChecker spellChecker = controlSpellchecker.SpellChecker;
        DocumentSpellChecker documentSpellChecker = (DocumentSpellChecker)spellChecker;
        documentSpellChecker.AddDictionary(new RadEn_USDictionary(), new System.Globalization.CultureInfo("en-US"));
    }
     
    private void check_Click(object sender, RoutedEventArgs e)
    {
        RadSpellChecker.Check(this.WrittenBody, SpellCheckingMode.AllAtOnce);
    }

    If that doesn't work, we would greatly appreciate a demo project illustrating the problem.


    Best wishes,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Rav
    Rav avatar
    36 posts
    Member since:
    Nov 2011

    Posted 12 Jun 2011 Link to this post

    Hi Iva,

    Unfortunately this did not fix the issue.

    Rav
  5. Rav
    Rav avatar
    36 posts
    Member since:
    Nov 2011

    Posted 12 Jun 2011 Link to this post

    Hi Iva,

    I fixed the issue, actually the problem was in the registering of dictionary:

    ((DocumentSpellChecker)constrolSpellChecker1.SpellChecker).AddDictionary(
                    new RadEn_USDictionary(), new CultureInfo("en-US"));

    I'm in Australia so it should actually be this:

    ((DocumentSpellChecker)constrolSpellChecker1.SpellChecker).AddDictionary(
                    new RadEn_USDictionary(), new CultureInfo("en-AU"));

    I didn't realise this was such an important parameter, in fact I still don't even know what that CultureInfo affects. Some clearer documentation would help.

    Thanks for your help

    Rav
  6. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 13 Jun 2011 Link to this post

    Hi Rav Panchalingam,

    It is good to hear that you have managed to solve the issue.
    You can find the online documentation of RadSpellChecker here. There is also an article about the multi-language support that describes how dictionaries are mapped to different instances of CultureInfo. RadSpellChecker uses the dictionary that is associated with the culture that is set as its SpellCheckingCulture property or (as in your case) the current UI culture of the thread.
    A neater solution than mapping an en-US dictionary to the en-AU culture would be to set the SpellCheckingCulture property of the spell checker to en-US like this:

    IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(RadRichTextBox));
    ISpellChecker spellChecker = controlSpellchecker.SpellChecker;
    DocumentSpellChecker documentSpellChecker = (DocumentSpellChecker)spellChecker;
    documentSpellChecker.AddDictionary(new RadEn_USDictionary(), new System.Globalization.CultureInfo("en-US"));
    documentSpellChecker.SpellCheckingCulture = new System.Globalization.CultureInfo("en-US");

    Best wishes,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner