Exemplo n.º 1
0
        protected void OnContextMenuOpening(object sender, RoutedEventArgs e)
        {
            if (Checker.MisspelledWords.Any(w => SelectionStart >= w.Index && SelectionStart <= w.Index + w.Length))
            {
                Checker.SelectedMisspelledWord = Checker.MisspelledWords.First(w => SelectionStart >= w.Index && SelectionStart <= w.Index + w.Length);
            }
            else
            {
                Checker.SelectedMisspelledWord = null;
            }

            this.ContextMenu.Items.Clear();
            foreach (var item in Checker.MenuActions)
            {
                var mi = new MenuItem();
                mi.Header  = item.Name;
                mi.Command = item.Command;
                this.ContextMenu.Items.Add(mi);
            }

            if (Checker.SelectedMisspelledWord != null)
            {
                ContextMenu.Items.Add(new Separator());

                ContextMenu.Items.Add(new MenuItem
                {
                    Header  = "Add to dictionary",
                    Command = new DelegateCommand(o =>
                    {
                        Checker.AddToDictionary(Checker.SelectedMisspelledWord.Text);
                        Checker.CheckSpelling(this.Text);
                        RaiseSpellcheckCompletedEvent();
                    }),
                });
            }
        }