WPF ComboBox, power input in UpperCase

I have an editable WPF ComboBox with TextSearchEnabled. I need to force user input in uppercase when they type to filter ComboBox.

I was thinking about changing the text box that is part of the control (named "PART_EditableTextBox") to set CharacterCasing = "Top" , however I cannot figure out how to do this.

Do I need to use a trigger or change the template in any way?

+3
source share
4 answers

This works and seems like a smart solution:

protected void winSurveyScreen_Loaded(object sender, RoutedEventArgs e) { (comboBox.Template.FindName("PART_EditableTextBox", cbObservation) as TextBox).CharacterCasing = CharacterCasing.Upper; } 

Make sure that combobox is not reset when loading, otherwise the template will not be found.

+8
source

IMO, a faster way is to set the UpdateTrigger in the PropertyChanged and to smooth the value in the data object when it is updated.

+3
source

I found that post is where a nested property is used. This allows you to use this for your entire ComboBox without rewriting code.

+1
source
 private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { Textbox editableTextbox = sender as Textbox; foreach (char ch in e.Text) { if (Char.IsLower(ch)) { editableTextbox.Text += Char.ToUpper(ch); e.Handled = true; } } } 

or try creating an attached behavior for the text box

-1
source

All Articles