예제 #1
0
        protected override void ColorizeLine(DocumentLine line)
        {
            lock (staticTextBox)
            {
                staticTextBox.Text = CurrentContext.Document.Text;
                int start = line.Offset;
                int end   = line.EndOffset;
                start = staticTextBox.GetNextSpellingErrorCharacterIndex(start, LogicalDirection.Forward);
                while (start < end)
                {
                    if (start == -1)
                    {
                        break;
                    }

                    int wordEnd = start + staticTextBox.GetSpellingErrorLength(start);

                    SpellingError error = staticTextBox.GetSpellingError(start);
                    if (error != null)
                    {
                        base.ChangeLinePart(start, wordEnd, (VisualLineElement element) => element.TextRunProperties.SetTextDecorations(collection));
                    }

                    start = staticTextBox.GetNextSpellingErrorCharacterIndex(wordEnd, LogicalDirection.Forward);
                }
            }
        }
예제 #2
0
        protected void btnOK_Click(object sender, RoutedEventArgs args)
        {
            if (CheckPassword())
            {
                string spellingHints = string.Empty;

                // Try to get a spelling error at the current caret location.
                SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);
                if (error != null)
                {
                    // Build a string of spelling suggestions.
                    foreach (string s in error.Suggestions)
                    {
                        spellingHints += string.Format("{0}\n", s);
                    }

                    // Show suggestions.
                    MessageBox.Show(spellingHints, "Try these instead");
                }
            }
            else
            {
                MessageBox.Show("Security error!!");
            }
        }
예제 #3
0
        // Helper to add speller menu items.
        private void AddSpellerMenuItems()
        {
            TextPointer mousePosition = this.GetMousePosition();

            if (mousePosition != null)
            {
                SpellingError spellingError = _myRichTextBox.GetSpellingError(mousePosition);
                if (spellingError != null)
                {
                    foreach (string suggestion in spellingError.Suggestions)
                    {
                        MenuItem menuItem = new MenuItem();
                        menuItem.Header           = suggestion;
                        menuItem.FontWeight       = FontWeights.Bold;
                        menuItem.Command          = EditingCommands.CorrectSpellingError;
                        menuItem.CommandParameter = suggestion;
                        menuItem.CommandTarget    = _myRichTextBox;
                        this.Items.Add(menuItem);
                    }

                    this.AddSeperator();
                    MenuItem ignoreAllMenuItem = new MenuItem();
                    ignoreAllMenuItem.Header        = EditingCommands.IgnoreSpellingError.Text;
                    ignoreAllMenuItem.Command       = EditingCommands.IgnoreSpellingError;
                    ignoreAllMenuItem.CommandTarget = _myRichTextBox;

                    this.AddSeperator();
                }
            }
        }
예제 #4
0
        // Token: 0x060038D8 RID: 14552 RVA: 0x00100E4C File Offset: 0x000FF04C
        private static bool IsErrorAtNonMergeableInlineEdge(SpellingError spellingError, out ITextPointer textStart, out ITextPointer textEnd)
        {
            bool result = false;

            textStart = spellingError.Start.CreatePointer(LogicalDirection.Backward);
            while (textStart.CompareTo(spellingError.End) < 0 && textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text)
            {
                textStart.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            textEnd = spellingError.End.CreatePointer();
            while (textEnd.CompareTo(spellingError.Start) > 0 && textEnd.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.Text)
            {
                textEnd.MoveToNextContextPosition(LogicalDirection.Backward);
            }
            if (textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text || textStart.CompareTo(spellingError.End) == 0)
            {
                return(false);
            }
            Invariant.Assert(textEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text && textEnd.CompareTo(spellingError.Start) != 0);
            if ((TextPointerBase.IsAtNonMergeableInlineStart(textStart) || TextPointerBase.IsAtNonMergeableInlineEnd(textEnd)) && typeof(Run).IsAssignableFrom(textStart.ParentType) && textStart.HasEqualScope(textEnd))
            {
                result = true;
            }
            return(result);
        }
예제 #5
0
        private static void TextBoxBaseContextMenuOpening(TextBoxBase sender, ContextMenuEventArgs e)
        {
            SpellingError spellingError;
            TextBoxBase   defaultTextBoxBaseContextMenu = (TextBoxBase)sender;
            TextBox       textBox     = defaultTextBoxBaseContextMenu as TextBox;
            RichTextBox   richTextBox = defaultTextBoxBaseContextMenu as RichTextBox;

            defaultTextBoxBaseContextMenu.ContextMenu = TextBoxHelper.GetDefaultTextBoxBaseContextMenu();
            int num = 0;

            if (textBox != null)
            {
                spellingError = textBox.GetSpellingError(textBox.CaretIndex);
            }
            else if (richTextBox != null)
            {
                spellingError = richTextBox.GetSpellingError(richTextBox.CaretPosition);
            }
            else
            {
                spellingError = null;
            }
            SpellingError spellingError1 = spellingError;

            if (spellingError1 != null)
            {
                IEnumerable <string> suggestions = spellingError1.Suggestions;
                if (suggestions.Any <string>())
                {
                    foreach (string suggestion in suggestions)
                    {
                        MenuItem menuItem = new MenuItem()
                        {
                            Header           = suggestion,
                            FontWeight       = FontWeights.Bold,
                            Command          = EditingCommands.CorrectSpellingError,
                            CommandParameter = suggestion,
                            CommandTarget    = defaultTextBoxBaseContextMenu
                        };
                        menuItem.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
                        defaultTextBoxBaseContextMenu.ContextMenu.Items.Insert(num, menuItem);
                        num++;
                    }
                    defaultTextBoxBaseContextMenu.ContextMenu.Items.Insert(num, new Separator());
                    num++;
                }
                MenuItem menuItem1 = new MenuItem()
                {
                    Header        = "Ignore All",
                    Command       = EditingCommands.IgnoreSpellingError,
                    CommandTarget = defaultTextBoxBaseContextMenu
                };
                menuItem1.SetResourceReference(FrameworkElement.StyleProperty, "MetroMenuItem");
                defaultTextBoxBaseContextMenu.ContextMenu.Items.Insert(num, menuItem1);
                num++;
                Separator separator = new Separator();
                defaultTextBoxBaseContextMenu.ContextMenu.Items.Insert(num, separator);
            }
        }
        /// <summary>
        /// Updates the spell check context menu items.
        /// </summary>
        private void UpdateSpellCheckContextMenuItems()
        {
            // Process items for spell-checking if SpellCheck.IsEnabled = true
            if ((this.ContextMenu != null) && (this.ContextMenu.ItemsSource == null))
            {
                RibbonControls.Menu menu = null;
                if (this.ContextMenu.Items.Count > 0)
                {
                    // Get an existing menu
                    menu = this.ContextMenu.Items[0] as RibbonControls.Menu;
                    if ((menu != null) && (!"SpellingErrors".Equals(menu.Tag)))
                    {
                        menu = null;
                    }
                }

                if (menu != null)
                {
                    // Clear the items
                    menu.Items.Clear();
                }
                else
                {
                    // Create a new menu
                    menu     = new RibbonControls.Menu();
                    menu.Tag = "SpellingErrors";
                    this.ContextMenu.Items.Insert(0, menu);
                }

                // If spell check is enabled...
                if (this.SpellCheck.IsEnabled)
                {
                    // Get the spelling error at the caret
                    SpellingError error = this.GetSpellingError(this.CaretPosition);
                    if (error != null)
                    {
                        // Add suggestion items
                        foreach (string suggestion in error.Suggestions)
                        {
                            RibbonControls.Button button = new RibbonControls.Button();
                            button.Command          = EditingCommands.CorrectSpellingError;
                            button.CommandParameter = suggestion;
                            button.Label            = suggestion;
                            menu.Items.Add(button);
                        }

                        // Add separator
                        if (menu.Items.Count > 0)
                        {
                            menu.Items.Add(new RibbonControls.Separator());
                        }
                    }
                }

                // Update visibility
                menu.Visibility = (this.SpellCheck.IsEnabled && (menu.Items.Count > 0) ? Visibility.Visible : Visibility.Collapsed);
            }
        }
예제 #7
0
        private void Expander_Expamded(object sender, RoutedEventArgs e)
        {
            SpellingError spellingError = tBox.GetSpellingError(tBox.CaretIndex);

            foreach (var item in spellingError.Suggestions)
            {
                spellList.Items.Add(item);
            }
        }
예제 #8
0
 private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
 {
     //MessageBox.Show("test");
     if (e.Button != System.Windows.Forms.MouseButtons.Right)
     {
         return;
     }
     //if ((e.Button & System.Windows.Forms.MouseButtons.Right) != System.Windows.Forms.MouseButtons.None)
     try
     {
         int i = 1;
         //int i = richTextBox1.Text.LastIndexOf(' ', 0, richTextBox1.SelectionStart);
         i = findprevspace(richTextBox1.Text, richTextBox1.SelectionStart);
         if (i == -1)
         {
             i = 0;
         }
         i++;
         //if (i > 0)
         {
             //SpellingError SE = T.GetSpellingError(richTextBox1.SelectionStart);
             SpellingError SE    = T.GetSpellingError(i);
             bool          error = T.GetSpellingErrorStart(i) >= 0;
             if (error)
             {
                 //MessageBox.Show(SE.Suggestions.ToArray()[0]);
                 string   S  = "";
                 string[] SG = SE.Suggestions.ToArray();
                 contextMenuStrip1.Items.Clear();
                 if (SG.Length > 0)
                 {
                     S = SG[0];
                     for (int j = 1; j < SG.Length; j++)
                     {
                         //S = S + "\n" + SG[j];
                         contextMenuStrip1.Items.Add(SG[j]);
                     }
                 }
                 contextMenuStrip1.Show(Cursor.Position);
                 //toolTip1.Show("Spelling suggestions:"+S,this,2000);
                 //toolTip1.AutomaticDelay = 1000000;
                 //toolTip1.SetToolTip(richTextBox1, "Spelling suggestions:\n" + S);
                 //toolTip1.Show("Spelling suggestions:" + S, this, 10000);
             }
             else
             {
                 //toolTip1.SetToolTip(richTextBox1, null);
             }
         }
     }
     catch
     {
     }
 }
예제 #9
0
        // Token: 0x060038DA RID: 14554 RVA: 0x00100F68 File Offset: 0x000FF168
        private static void OnQueryStatusSpellingError(object target, CanExecuteRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null)
            {
                return;
            }
            SpellingError spellingErrorAtSelection = TextEditorSpelling.GetSpellingErrorAtSelection(textEditor);

            args.CanExecute = (spellingErrorAtSelection != null);
        }
예제 #10
0
        private void BtnBrowse_Click(object sender, RoutedEventArgs e)
        {
            SpellingError error = textbox.GetSpellingError(textbox.CaretIndex);

            if (error != null)
            {
                foreach (var item in error.Suggestions)
                {
                    listBox.Items.Add(item);
                }
            }
        }
        /// <summary>
        /// Runs the spell checking for a miss-spelled word.
        /// </summary>
        /// <param name="spellingError">The current spelling error.</param>
        /// <param name="suggestions">The suggestions for the miss-spelled word.</param>
        /// <param name="location">The location where the spell checking is going at.</param>
        /// <param name="count">The count of total spell checks.</param>
        /// <returns><c>true</c> if the spell check loop should continue, <c>false</c> otherwise.</returns>
        public bool RunSpellCheck(SpellingError spellingError, List <string> suggestions, int location, int count)
        {
            listSuggestions.Items.Clear();
            listSuggestions.Items.AddRange(suggestions.ToArray().ToArray <object>());
            SpellingError = spellingError;

            lbWordCountValue.Text = $@"{location} / {count}";

            var result = ShowDialog(OwnerWindow) != DialogResult.Cancel;

            return(result);
        }
예제 #12
0
 /**
  * Function that return next error
  */
 public void NextCorrection()
 {
     try
     {
         this.nextError = this.parent.TextEdit.GetNextSpellingErrorPosition(nextError, LogicalDirection.Forward);
         this.spErr     = this.parent.TextEdit.GetSpellingError(this.nextError);
     }
     catch (ArgumentNullException)
     {
         this.Close();
     }
 }
예제 #13
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SpellingError spellingError = txtText.GetSpellingError(txtText.CaretIndex);

            if (spellingError != null)
            {
                lblText.Content = "";
                foreach (var item in spellingError.Suggestions)
                {
                    lblText.Content += $"{item}\n";
                }
            }
        }
예제 #14
0
        private void RichTextBoxContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            var menuItems = new List <Control>();

            SpellingError spellingError = richTextBox.GetSpellingError(richTextBox.CaretPosition);

            if (spellingError != null)
            {
                foreach (string suggestion in spellingError.Suggestions.Take(5))
                {
                    var menuItem = new MenuItem()
                    {
                        Header           = suggestion,
                        FontWeight       = FontWeights.Bold,
                        Command          = EditingCommands.CorrectSpellingError,
                        CommandParameter = suggestion
                    };
                    menuItems.Add(menuItem);
                }

                if (!menuItems.Any())
                {
                    var noSpellingSuggestions = new MenuItem()
                    {
                        Header     = Properties.Resources.NoSpellingSuggestions,
                        FontWeight = FontWeights.Bold,
                        IsEnabled  = false,
                    };
                    menuItems.Add(noSpellingSuggestions);
                }

                menuItems.Add(new Separator());

                var ignoreAllMenuItem = new MenuItem()
                {
                    Header  = Properties.Resources.IgnoreAllMenu,
                    Command = EditingCommands.IgnoreSpellingError
                };
                menuItems.Add(ignoreAllMenuItem);

                menuItems.Add(new Separator());
            }

            foreach (var item in menuItems.Reverse <Control>())
            {
                contextMenu.Items.Insert(0, item);
            }

            dynamicContextMenuItems = menuItems;
        }
        private void ToolsSpellingHints_Click(object sender, RoutedEventArgs e)
        {
            string        spellingHints = string.Empty;
            SpellingError error         = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    spellingHints += string.Format("{0}\n", s);
                }
                lblSpellingHints.Content    = spellingHints;
                expanderSpelling.IsExpanded = true;
            }
        }
예제 #16
0
        protected void ToolsSpellingHints_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder hints = new StringBuilder();
            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    hints.AppendLine(s);
                }
            }
            lblSpellingHints.Content    = hints.ToString();
            expanderSpelling.IsExpanded = true;
        }
예제 #17
0
        protected override void ColorizeLine(DocumentLine line)
        {
            if (el)
            {
                //if (line.LineNumber == CurrentContext.Document.LineCount - 1)
                //{
                //el = false;
                //}

                lock (staticTextBox)
                {
                    try
                    {
                        //if (string.IsNullOrEmpty(t))
                        //    t = "";
                        staticTextBox.Text = CurrentContext.Document.GetText(line.Offset, line.Length); //CurrentContext.Document.Text;
                        int start = 0;                                                                  // line.Offset;
                        int end   = line.Length;                                                        //.EndOffset;
                        start = staticTextBox.GetNextSpellingErrorCharacterIndex(start, LogicalDirection.Forward);
                        while (start < end)
                        {
                            if (start == -1)
                            {
                                break;
                            }
                            int wordEnd = start + line.Offset + staticTextBox.GetSpellingErrorLength(start);

                            SpellingError error = staticTextBox.GetSpellingError(start);
                            if (error != null)
                            {
                                base.ChangeLinePart(start + line.Offset, wordEnd, (VisualLineElement element) => element.TextRunProperties.SetTextDecorations(collection));
                            }

                            start = staticTextBox.GetNextSpellingErrorCharacterIndex(wordEnd - line.Offset, LogicalDirection.Forward);
                            el    = false;
                        }
                    }
                    catch (System.Exception ex)
                    {
                    }
                }
            }
            else
            {
                //el = true;
                //tmr.Stop();
            }
        }
예제 #18
0
        // Spell Check Assistant
        private void CheckSpellingHints(object sender, RoutedEventArgs e)
        {
            string spellingHints = string.Empty;

            SpellingError error = textBox.GetSpellingError(textBox.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    spellingHints += string.Format("{0}\n", s);
                }
            }
            variantSpellingHints.Content = spellingHints;
            expandr.IsExpanded           = true;
        }
예제 #19
0
        // Token: 0x060038D9 RID: 14553 RVA: 0x00100F3C File Offset: 0x000FF13C
        private static void OnIgnoreSpellingError(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null)
            {
                return;
            }
            SpellingError spellingErrorAtSelection = TextEditorSpelling.GetSpellingErrorAtSelection(textEditor);

            if (spellingErrorAtSelection == null)
            {
                return;
            }
            spellingErrorAtSelection.IgnoreAll();
        }
예제 #20
0
        // Token: 0x060038D7 RID: 14551 RVA: 0x00100D38 File Offset: 0x000FEF38
        private static void OnCorrectSpellingError(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null)
            {
                return;
            }
            string text = args.Parameter as string;

            if (text == null)
            {
                return;
            }
            SpellingError spellingErrorAtSelection = TextEditorSpelling.GetSpellingErrorAtSelection(textEditor);

            if (spellingErrorAtSelection == null)
            {
                return;
            }
            using (textEditor.Selection.DeclareChangeBlock())
            {
                ITextPointer textPointer;
                ITextPointer position;
                bool         flag = TextEditorSpelling.IsErrorAtNonMergeableInlineEdge(spellingErrorAtSelection, out textPointer, out position);
                ITextPointer textPointer2;
                if (flag && textPointer is TextPointer)
                {
                    ((TextPointer)textPointer).DeleteTextInRun(textPointer.GetOffsetToPosition(position));
                    textPointer.InsertTextInRun(text);
                    textPointer2 = textPointer.CreatePointer(text.Length, LogicalDirection.Forward);
                }
                else
                {
                    textEditor.Selection.Select(spellingErrorAtSelection.Start, spellingErrorAtSelection.End);
                    if (textEditor.AcceptsRichContent)
                    {
                        ((TextSelection)textEditor.Selection).SpringloadCurrentFormatting();
                    }
                    XmlLanguage xmlLanguage = (XmlLanguage)spellingErrorAtSelection.Start.GetValue(FrameworkElement.LanguageProperty);
                    textEditor.SetSelectedText(text, xmlLanguage.GetSpecificCulture());
                    textPointer2 = textEditor.Selection.End;
                }
                textEditor.Selection.Select(textPointer2, textPointer2);
            }
        }
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            string spellingHints = string.Empty;

            //try to  get a spelling error at the current caret location
            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    spellingHints += $"{s}\n";
                }
                lblSpellingHints.Content    = spellingHints;
                expanderSpelling.IsExpanded = true;
            }
        }
예제 #22
0
파일: Extensions.cs 프로젝트: yk2012985/wpf
        internal static List <SpellingError> ToList(
            this IEnumSpellingError spellingErrors,
            SpellChecker spellChecker,
            string text,
            bool shouldSuppressCOMExceptions = true,
            bool shouldReleaseCOMObject      = true)
        {
            if (spellingErrors == null)
            {
                throw new ArgumentNullException(nameof(spellingErrors));
            }

            var result = new List <SpellingError>();

            try
            {
                while (true)
                {
                    ISpellingError iSpellingError = spellingErrors.Next();

                    if (iSpellingError == null)
                    {
                        // no more ISpellingError objects left in the enum
                        break;
                    }

                    var error = new SpellingError(iSpellingError, spellChecker, text, shouldSuppressCOMExceptions, true);
                    result.Add(error);
                }
            }
            catch (COMException) when(shouldSuppressCOMExceptions)
            {
                // do nothing here
                // the exception filter does it all.
            }
            finally
            {
                if (shouldReleaseCOMObject)
                {
                    Marshal.ReleaseComObject(spellingErrors);
                }
            }

            return(result);
        }
예제 #23
0
        private void ToolsSpellingHints_Click(object sender, RoutedEventArgs e)
        {
            string spellingHints = string.Empty;
            // Try to get a spelling error at the current caret location.
            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                // Build a string of spelling suggestions.
                foreach (string s in error.Suggestions)
                {
                    spellingHints += string.Format("{0}\n", s);
                }
                // Show suggestions and expand the expander.
                lblSpellingHints.Content    = spellingHints;
                expanderSpelling.IsExpanded = true;
            }
        }
        private void MainTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            MainTextBox.ContextMenu.Items.Clear();
            SpellingError spellingError = MainTextBox.GetSpellingError(MainTextBox.CaretPosition);

            if (spellingError != null && spellingError.Suggestions.Count() > 0)
            {
                foreach (string suggestion in spellingError.Suggestions)
                {
                    MenuItem menuItem = new MenuItem();
                    menuItem.Header           = suggestion;
                    menuItem.FontWeight       = FontWeights.Bold;
                    menuItem.Command          = EditingCommands.CorrectSpellingError;
                    menuItem.CommandParameter = suggestion;
                    menuItem.CommandTarget    = MainTextBox;
                    MainTextBox.ContextMenu.Items.Add(menuItem);
                }
            }
            else if (spellingError != null)
            {
                MenuItem menuItem = new MenuItem();
                menuItem.Header    = "No Suggestions";
                menuItem.IsEnabled = false;
                MainTextBox.ContextMenu.Items.Add(menuItem);
            }
            if (spellingError != null)
            {
                Separator separator = new Separator();
                MainTextBox.ContextMenu.Items.Add(separator);

                MenuItem addToDictionary = new MenuItem();
                addToDictionary.Header = "Add to Dictionary";
                var tr = MainTextBox.GetSpellingErrorRange(MainTextBox.CaretPosition);
                addToDictionary.Click += (object o, RoutedEventArgs args) =>
                {
                    _spellcheckDictionary.AddToDictionary(tr.Text);
                };
                MainTextBox.ContextMenu.Items.Add(addToDictionary);
            }
            else
            {
                e.Handled = true;
            }
        }
예제 #25
0
        void ApplySelectedSuggestion()
        {
            if (!this.AreSuggestionsVisible || this.suggestionList.SelectedIndex < 0)
            {
                return;
            }

            SpellingError error = this.GetSpellingError();

            if (error != null)
            {
                string correctWord = this.suggestionList.SelectedItem as string;
                error.Correct(correctWord);
                base.CaretIndex = this.FindEndOfCurrentWord();
                base.Focus();
            }

            this.HideSuggestions();
        }
예제 #26
0
        private void ToolsSpellingHints_Click(object sender, RoutedEventArgs e)
        {
            string spellingHints = string.Empty;

            // look for spelling errors at the current caret location
            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    spellingHints += string.Format("{0}\n", s);
                }

                // show suggestions and expand the expander
                lblSpellingHints.Content    = spellingHints;
                ExpanderSpelling.IsExpanded = true;
            }
        }
예제 #27
0
        private void ApplySelectedSuggestion()
        {
            if (!AreSuggestionsVisible || suggestionList.SelectedIndex < 0)
            {
                return;
            }

            SpellingError error = GetSpellingError();

            if (error != null)
            {
                var correctWord = suggestionList.SelectedItem as string;
                error.Correct(correctWord);
                CaretIndex = FindEndOfCurrentWord();
                Focus();
            }

            HideSuggestions();
        }
        private void VerifyWord(String valueToVerify)
        {
            string  suggestionsForExpander = String.Empty;
            TextBox txt = new TextBox();

            txt.SpellCheck.IsEnabled = true;
            txt.Text = valueToVerify.ToLower();
            SpellingError result = txt.GetSpellingError(0);

            if (result != null)
            {
                foreach (string s in result.Suggestions)
                {
                    suggestionsForExpander += string.Format("{0}\n", s);
                }
            }

            expanderSuggestions.Content    = suggestionsForExpander;
            expanderSuggestions.IsExpanded = true;
        }
        protected void ToolsSpellingHints_Click(object sender, RoutedEventArgs args)
        {
            string spellingHints = string.Empty;

            //  获取当前位置的拼写错误
            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                //  构建更改建议的字符串
                foreach (string s in error.Suggestions)
                {
                    spellingHints += string.Format("{0}\n", s);
                }

                //  显示建议和扩展Expander
                lblSpellingHints.Content    = spellingHints;
                expanderSpelling.IsExpanded = true;
            }
        }
예제 #30
0
        private void ToolsSpellingHints_Click(object sender, RoutedEventArgs e)
        {
            string spellingHints = string.Empty;

            SpellingError error = txtData.GetSpellingError(txtData.CaretIndex);

            if (error != null)
            {
                foreach (string s in error.Suggestions)
                {
                    spellingHints += $"{s}\n";
                }

                lblSpellingHints.Content    = spellingHints;
                expanderSpelling.IsExpanded = true;
            }
            else
            {
                MessageBox.Show("No spelling suggestions found.");
            }
        }