WPF ComboBox, force input to UpperCase

后端 未结 4 1182
孤城傲影
孤城傲影 2021-01-20 05:45

I have an editable WPF ComboBox with TextSearchEnabled. I need to force the user\'s text input to uppercase when they type to filter the ComboBox.

I was thinking of

4条回答
  •  有刺的猬
    2021-01-20 06:27

    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 behaviour for the textbox

提交回复
热议问题