Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply spell checking for Editable ComboBox in WPF

WPF comes with an inbuilt feature of SpellCheck. SpellCheck is added to TextBoxBase object, which inherits all the textual input controls automatically. Thus any input control will automatically derive the Spell Checking functionality.

But I'm looking for a solution to set the spell checker for editable ComboBox which is not inherited from the TextBoxBase.Are there any way to set the spell check for Editable ComboBox controller ?

like image 415
Thilina H Avatar asked Jun 05 '14 07:06

Thilina H


1 Answers

You will need to declare your own ControlTemplate for the ComboBox. In that ControlTemplate, you can start with the default ControlTemplate for the ComboBox, which you can find on the ComboBox Styles and Templates page on MSDN.

In the default template, you should see a TextBox named PART_EditableTextBox... as you might have guessed, this is the editable part of the ComboBox. Then all you need to do is to set the SpellCheck.IsEnabled Attached Property to True on it and apply your new ControlTemplate as your ComboBox.Template value:

<TextBox x:Name="PART_EditableTextBox" 
               SpellCheck.IsEnabled="True"
               Style="{x:Null}"
               Template="{StaticResource ComboBoxTextBox}"
               HorizontalAlignment="Left"
               VerticalAlignment="Bottom"
               Margin="3,3,23,3"
               Focusable="True"
               Background="Transparent"
               Visibility="Hidden"
               IsReadOnly="{TemplateBinding IsReadOnly}" />
like image 108
Sheridan Avatar answered Nov 14 '22 22:11

Sheridan