//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="textBox">The text box with which this spell checker is associated</param> private WpfTextBoxSpellChecker(TextBox textBox) { this.textBox = textBox; System.Diagnostics.Debug.WriteLine("******* Connecting to " + ElementName(textBox) + " *******"); lock (syncRoot) { wordSplitter = new WordSplitter { Configuration = configuration, Classification = RangeClassification.PlainText }; } misspelledWords = new List <FileMisspelling>(); var adornerLayer = AdornerLayer.GetAdornerLayer(textBox); if (adornerLayer != null) { timer = new Timer(500) { Interval = 500, AutoReset = false }; timer.Elapsed += timer_Elapsed; adorner = new SpellingErrorAdorner(textBox); adornerLayer.Add(adorner); textBox.TextChanged += this.textBox_TextChanged; if (textBox.ContextMenu == null) { var cm = new ContextMenu(); cm.Items.Add(new MenuItem { Command = ApplicationCommands.Copy }); cm.Items.Add(new MenuItem { Command = ApplicationCommands.Cut }); cm.Items.Add(new MenuItem { Command = ApplicationCommands.Paste }); textBox.ContextMenu = cm; } textBox.ContextMenu.Opened += this.textBox_ContextMenuOpeningHandler; var window = Window.GetWindow(textBox); // For normal forms, disconnect the spell checker when the window closes if (window != null && !window.GetType().FullName.StartsWith("Microsoft.VisualStudio.", StringComparison.OrdinalIgnoreCase)) { window.Closing += window_Closing; } this.textBox_TextChanged(this, null); } }