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

Dictionary not adding in MEF

4 Answers 118 Views
SpellChecker
This is a migrated thread and some comments may be shown as answers.
Rav
Top achievements
Rank 2
Rav asked on 05 Jun 2011, 10:25 AM
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

4 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 09 Jun 2011, 09:39 AM
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
0
Rav
Top achievements
Rank 2
answered on 12 Jun 2011, 05:28 AM
Hi Iva,

Unfortunately this did not fix the issue.

Rav
0
Rav
Top achievements
Rank 2
answered on 12 Jun 2011, 05:36 AM
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
0
Iva Toteva
Telerik team
answered on 13 Jun 2011, 09:38 AM
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
Tags
SpellChecker
Asked by
Rav
Top achievements
Rank 2
Answers by
Iva Toteva
Telerik team
Rav
Top achievements
Rank 2
Share this question
or