GetDefaultTextBoxBaseContextMenu() private static method

private static GetDefaultTextBoxBaseContextMenu ( ) : System.Windows.Controls.ContextMenu
return System.Windows.Controls.ContextMenu
Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        private static void UseSpellCheckContextMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBoxBase defaultTextBoxBaseContextMenu = d as TextBoxBase;

            if (defaultTextBoxBaseContextMenu == null)
            {
                throw new InvalidOperationException("The property 'IsSpellCheckContextMenuEnabled' may only be set on TextBoxBase elements.");
            }
            if ((bool)e.NewValue)
            {
                defaultTextBoxBaseContextMenu.SetValue(SpellCheck.IsEnabledProperty, (object)true);
                defaultTextBoxBaseContextMenu.ContextMenu         = TextBoxHelper.GetDefaultTextBoxBaseContextMenu();
                defaultTextBoxBaseContextMenu.ContextMenuOpening += new ContextMenuEventHandler(TextBoxHelper.TextBoxBaseContextMenuOpening);
                return;
            }
            defaultTextBoxBaseContextMenu.SetValue(SpellCheck.IsEnabledProperty, (object)false);
            defaultTextBoxBaseContextMenu.ContextMenu         = TextBoxHelper.GetDefaultTextBoxBaseContextMenu();
            defaultTextBoxBaseContextMenu.ContextMenuOpening -= new ContextMenuEventHandler(TextBoxHelper.TextBoxBaseContextMenuOpening);
        }