WPF ComboBox,强制输入到大写 [英] WPF ComboBox, force input to UpperCase

查看:23
本文介绍了WPF ComboBox,强制输入到大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 TextSearchEnabled 的可编辑 WPF ComboBox.我需要在用户输入时强制将用户的文本输入为大写以过滤 ComboBox.

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.

我想修改作为控件一部分的文本框(名为PART_EditableTextBox")以设置 CharacterCasing="Upper",但是我不太清楚如何执行此操作.

I was thinking of modifying the textbox that is part of the control (named 'PART_EditableTextBox') to set CharacterCasing="Upper", however I can't quite figure out how to do this.

我是否需要使用触发器或以某种方式修改模板?

Do I need to use a trigger, or modify the template in some way?

推荐答案

这有效并且似乎是一个合理的解决方案:

This works and seems like a reasonable solution:

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

确保组合框在加载时未折叠,否则将找不到模板.

Ensure that the combobox is not collapsed on loaded otherwise the template will not be found.

这篇关于WPF ComboBox,强制输入到大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆