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

Change dictionary causes null ref exception in RadWindow

4 Answers 78 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 26 Nov 2012, 06:12 PM
Hi,

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:
  1. Comment out LoadDictionary() method call   (loads RadWindow with a taskbar icon but doesn't change dictionary)
  2. 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



4 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 28 Nov 2012, 09:48 AM
Hi Robert,

 Indeed this exception is thrown when you load the window. It is a bug and it will be fixed in our SP1 release which is about to come out every moment now. As a workaround you can try loading the dictionary before you instantiate RadWindowHelper2. That means first you call:

//Set dictionary to English GB
    Stream stream = Application.GetResourceStream(new Uri("en-GB.tdf", UriKind.RelativeOrAbsolute)).Stream;
    this.LoadDictionary(stream);
and then call
//Make RadWindow a normal window (to show taskbar icon etc)
    RadWindowHelper2 windowHelper = new RadWindowHelper2();
    windowHelper.TaskBarDisplayed += new EventHandler(windowHelper_TaskBarDisplayed);
    windowHelper.ShowWindowInTaskBar();
All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 28 Nov 2012, 11:06 AM
Hi Andrew,

Thanks for getting back to me.
I did as you suggested and it solved the null reference exception.

However, it seems that the dictionary isn't taking hold. For example, I spell "Colour" or "Color" and the spell check doesn't detect either of them and offers no solution.

Putting the null reference exception work around to the side, the problem with the dictionary displaying no results still exists.
It used to work, at least up until the latest release.

Thanks again for your help Andrew,

Rob
0
Accepted
Andrew
Telerik team
answered on 29 Nov 2012, 03:39 PM
Hello Rob,

I tested this scenario by copying most of the code you posted with the latest Q3 version of our controls. 2012.3 1017. With the solution I proposed everything seems to work OK.

In order to investigate the problem, we will need a demo project illustrating the issue.Please open a support ticket and attach a demo, so that we can assist you further.

All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 29 Nov 2012, 11:48 PM
Hi Andrew,

After upgrading to the latest release the dictionary now appears to work again providing I load it before RadWindowHelper class.

Thanks again for your help,

Rob 
Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Robert
Top achievements
Rank 1
Share this question
or