|
2 | 2 | using System.Windows;
|
3 | 3 | using System.Windows.Controls;
|
4 | 4 | using System.Windows.Controls.Primitives;
|
| 5 | +using System.Windows.Documents; |
5 | 6 |
|
6 | 7 | namespace MaterialDesignThemes.Wpf
|
7 | 8 | {
|
@@ -46,7 +47,7 @@ public static Thickness GetTextBoxViewMargin(DependencyObject element)
|
46 | 47 | /// Controls the visibility of the underline decoration.
|
47 | 48 | /// </summary>
|
48 | 49 | public static readonly DependencyProperty DecorationVisibilityProperty = DependencyProperty.RegisterAttached(
|
49 |
| - "DecorationVisibility", typeof (Visibility), typeof (TextFieldAssist), new PropertyMetadata(default(Visibility))); |
| 50 | + "DecorationVisibility", typeof(Visibility), typeof(TextFieldAssist), new PropertyMetadata(default(Visibility))); |
50 | 51 |
|
51 | 52 | /// <summary>
|
52 | 53 | /// Controls the visibility of the underline decoration.
|
@@ -106,38 +107,60 @@ private static void TextBoxOnContextMenuOpening(object sender, ContextMenuEventA
|
106 | 107 |
|
107 | 108 | ContextMenu contextMenu = textBoxBase?.ContextMenu;
|
108 | 109 | if (contextMenu == null) return;
|
109 |
| - |
| 110 | + |
110 | 111 | RemoveSpellingSuggestions(contextMenu);
|
111 | 112 |
|
112 | 113 | if (!SpellCheck.GetIsEnabled(textBoxBase)) return;
|
113 | 114 |
|
114 | 115 | SpellingError spellingError = GetSpellingError(textBoxBase);
|
115 | 116 | if (spellingError != null)
|
116 | 117 | {
|
| 118 | + Style spellingSuggestionStyle = |
| 119 | + contextMenu.TryFindResource(Spelling.SpellingSuggestionMenuItemStyleKey) as Style; |
| 120 | + |
117 | 121 | int insertionIndex = 0;
|
118 | 122 | bool hasSuggestion = false;
|
119 | 123 | foreach (string suggestion in spellingError.Suggestions)
|
120 | 124 | {
|
121 | 125 | hasSuggestion = true;
|
122 |
| - var menuItem = new SpellingSuggestionMenuItem(suggestion) |
| 126 | + var menuItem = new MenuItem |
123 | 127 | {
|
124 |
| - CommandTarget = textBoxBase |
| 128 | + CommandTarget = textBoxBase, |
| 129 | + Command = EditingCommands.CorrectSpellingError, |
| 130 | + CommandParameter = suggestion, |
| 131 | + Style = spellingSuggestionStyle, |
| 132 | + Tag = typeof(Spelling) |
125 | 133 | };
|
126 | 134 | contextMenu.Items.Insert(insertionIndex++, menuItem);
|
127 | 135 | }
|
128 | 136 | if (!hasSuggestion)
|
129 | 137 | {
|
130 |
| - contextMenu.Items.Insert(insertionIndex++, new SpellingNoSuggestionsMenuItem()); |
| 138 | + contextMenu.Items.Insert(insertionIndex++, new MenuItem |
| 139 | + { |
| 140 | + Style = contextMenu.TryFindResource(Spelling.SpellingNoSuggestionsMenuItemStyleKey) as Style, |
| 141 | + Tag = typeof(Spelling) |
| 142 | + }); |
131 | 143 | }
|
132 | 144 |
|
133 |
| - contextMenu.Items.Insert(insertionIndex++, new Separator { Tag = typeof(SpellingSuggestionMenuItem) }); |
| 145 | + contextMenu.Items.Insert(insertionIndex++, new Separator |
| 146 | + { |
| 147 | + Style = contextMenu.TryFindResource(Spelling.SpellingSeparatorStyleKey) as Style, |
| 148 | + Tag = typeof(Spelling) |
| 149 | + }); |
134 | 150 |
|
135 |
| - contextMenu.Items.Insert(insertionIndex++, new SpellingIgnoreAllMenuItem |
| 151 | + contextMenu.Items.Insert(insertionIndex++, new MenuItem |
136 | 152 | {
|
137 |
| - CommandTarget = textBoxBase |
| 153 | + Command = EditingCommands.IgnoreSpellingError, |
| 154 | + CommandTarget = textBoxBase, |
| 155 | + Style = contextMenu.TryFindResource(Spelling.SpellingIgnoreAllMenuItemStyleKey) as Style, |
| 156 | + Tag = typeof(Spelling) |
138 | 157 | });
|
139 | 158 |
|
140 |
| - contextMenu.Items.Insert(insertionIndex, new Separator { Tag = typeof(SpellingSuggestionMenuItem) }); |
| 159 | + contextMenu.Items.Insert(insertionIndex, new Separator |
| 160 | + { |
| 161 | + Style = contextMenu.TryFindResource(Spelling.SpellingSeparatorStyleKey) as Style, |
| 162 | + Tag = typeof(Spelling) |
| 163 | + }); |
141 | 164 | }
|
142 | 165 | }
|
143 | 166 |
|
@@ -167,12 +190,8 @@ private static void TextBoxOnContextMenuClosing(object sender, ContextMenuEventA
|
167 | 190 |
|
168 | 191 | private static void RemoveSpellingSuggestions(ContextMenu menu)
|
169 | 192 | {
|
170 |
| - foreach (object item in (from item in menu.Items.OfType<object>() |
171 |
| - let separator = item as Separator |
172 |
| - where item is SpellingSuggestionMenuItem || |
173 |
| - item is SpellingIgnoreAllMenuItem || |
174 |
| - item is SpellingNoSuggestionsMenuItem || |
175 |
| - ReferenceEquals(separator?.Tag, typeof(SpellingSuggestionMenuItem)) |
| 193 | + foreach (FrameworkElement item in (from item in menu.Items.OfType<FrameworkElement>() |
| 194 | + where ReferenceEquals(item.Tag, typeof(Spelling)) |
176 | 195 | select item).ToList())
|
177 | 196 | {
|
178 | 197 | menu.Items.Remove(item);
|
|
0 commit comments