I'm having trouble changing the dictionary to en-GB when the RadRichTextBox control is hosted in a RadWindow rather than a standard window.
It will be easier to see some coding examples of my problem.
Initial Loading Code:
public Editor2(int _userID){ InitializeComponent(); //Set Language this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag); //Make RadWindow a normal window (to show taskbar icon etc) RadWindowHelper2 windowHelper = new RadWindowHelper2(); windowHelper.TaskBarDisplayed += new EventHandler(windowHelper_TaskBarDisplayed); windowHelper.ShowWindowInTaskBar(); //Set Document Styles RadDocumentStyles.AddStylesToDocumentRepository(this.radRichTextBox1.Document); //Set dictionary to English GB Stream stream = Application.GetResourceStream(new Uri("en-GB.tdf", UriKind.RelativeOrAbsolute)).Stream; this.LoadDictionary(stream);}Notice that I'm using a class called RadWindowHelper2 and a method windowHelper_TraskBarDisplayed(). I obtained this code somewhere in these forums so that a taskbar item is displayed.
At the end of the initial code I then call LoadDictionary() to change the dictionary to en-GB.
RadWindowsHelper2 class
public class RadWindowHelper2{ public event EventHandler TaskBarDisplayed; public void ShowWindowInTaskBar() { if (this.TaskBarDisplayed != null) { this.TaskBarDisplayed(this, new EventArgs()); } }}windowHelper_TaskBarDisplayed()
void windowHelper_TaskBarDisplayed(object sender, EventArgs e){ this.Show(); //this.WindowState = WindowState.Maximized; this.BringToFront(); var window = this.ParentOfType<Window>(); window.ShowInTaskbar = true; window.Title = "Template Editor (Printing)";}LoadDictionary()
private void LoadDictionary(Stream tdfFileStream){ RadDictionary dictionary = new RadDictionary(); dictionary.Load(tdfFileStream); ((DocumentSpellChecker)this.radRichTextBox1.SpellChecker).AddDictionary(dictionary, CultureInfo.CurrentUICulture);}I can get the window to load and radrichtextbox to show providing I do one of the following:
- Comment out LoadDictionary() method call (loads RadWindow with a taskbar icon but doesn't change dictionary)
- Comment out the code that creates an instance of RadWindowHelper2 (loads RadWindow without a taskbar icon but does change dictionary to en-GB)
For some reason I cannot get both of the above methods to load together.
Here's the exception and stack trace when I try to show a taskbar icon and change the dictionary to en-GB:
Exception:
NullReferenceException was unhandled
Object reference not set to an instance of an object.
stack trace:
call stack:
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.Layers.DecorationUILayerBase.UpdateViewPort(Telerik.Windows.Documents.UI.Layers.UILayerUpdateContext context = {unknown})
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.Layers.TextDecorationLayers.ProofingErrorsDecorationUILayer.ForceUpdateUIViewPort()
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.DocumentPagePresenter.UpdateProofingTextDecoration()
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.DocumentPrintLayoutPresenter.UpdateProofingTextDecoration()
Telerik.Windows.Documents.dll!Telerik.Windows.Controls.RadRichTextBox.InvalidateProofingErrors(bool invalidateIncorrectWordsOnly = {unknown})
Telerik.Windows.Documents.dll!Telerik.Windows.Controls.RadRichTextBox.spellChecker_DataChanged(object sender = {unknown}, System.EventArgs e = {unknown})
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Proofing.DocumentSpellChecker.OnDataChanged()
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Proofing.DocumentSpellChecker.AddCustomDictionary(Telerik.Windows.Documents.Proofing.ICustomWordDictionary customDictionary = {unknown}, System.Globalization.CultureInfo culture = {unknown})
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Proofing.DocumentSpellChecker.AddDictionary(System.Lazy<Telerik.Windows.Documents.Proofing.IWordDictionary> lazyDictionary = {unknown}, System.Globalization.CultureInfo culture = {unknown})
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Proofing.DocumentSpellChecker.AddDictionary(Telerik.Windows.Documents.Proofing.IWordDictionary dictionary = {unknown}, System.Globalization.CultureInfo culture = {unknown})
> TemplateEditor.exe!TemplateEditor.Editor2.LoadDictionary(System.IO.Stream tdfFileStream = {unknown})
TemplateEditor.exe!TemplateEditor.Editor2..ctor(int _userID = {unknown})
TAS2.exe!TAS2.SpecEditor.btnTemplateEditor_Click(object sender = {unknown}, System.Windows.RoutedEventArgs e = {unknown})
[External Code]
Any advice would be greatly appreciated.
Thanks,
Rob