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

SpellCheckingCompleted - Remove Event Handlers

0 Answers 66 Views
SpellChecker
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 2
Jason asked on 09 Jan 2013, 10:04 PM
Hello,
I recently had to deal with an issue related to the RadSpellChecker.SpellCheckingCompleted event handler, and was wishing to provide my thoughts on the issue.

Setup:
In the constructor for an example page of Page1.xaml, I add in an event handler for the SpellCheckingCompleted event, so that I may perform some custom processing after the spell check completes (Performing spell check on multiple text boxes using the RadSpellChecker.Check() function).

Workflow:
Go to page1, perform spell check.
Go to page2 (Any other page).
Go to page1, perform spell check.

Error:
As the RadSpellChecker is static, there are now two event handlers for the SpellCheckingCompleted event, one of which has gone out of scope and I am unable to remove. The original event handler contains a reference to the out-of-date private variables on the page, so the custom processing in this function fails, in addition to the second event handler performing processing.

I was unable to perform an if-then on the SpellCheckingComplete event handler to see if there is an existing event handler in SpellCheckingComplete, or if it was null (Shows compiler error - The event Telerik.Windows.Controls.RadSpellChecker.SpellCheckingCompleted can only appear on the left hand side of += or -=).

I ended up resolving this issue by having a static variable of EventHandler<Telerik.Windows.Documents.Proofing.SpellCheckingCompletedEventArgs> spellCheckEvent; on the page. On the constructor for the page, if this static variable was not empty, then I cleared the previous event handler for RadSpellChecker by performing a -= operation using the spellCheckEvent. Then I went ahead to create the new event handler, as normal.

Suggestion:
Providing a method to remove all event handlers for RadSpellCheck.SpellCheckingCompleted may aid developers on managing their event handlers and references to variables through navigation of different pages. (I read that from within the class which contains an event handler, you may set the event handler as null, but externally, the event handler cannot be set as null). My scenario may have been a unique one, but I still wished to provide insight on an resolution to an issue that may help other developers.

Thank you for your time,
Jason A.

No answers yet. Maybe you can help?

Tags
SpellChecker
Asked by
Jason
Top achievements
Rank 2
Share this question
or