WPF ComboBox,强制输入大写
我有一个带有 TextSearchEnabled 的可编辑 WPF ComboBox。当用户键入以过滤组合框时,我需要强制用户的文本输入为大写。
我正在考虑修改作为控件一部分的文本框(名为“PART_EditableTextBox”)以设置 CharacterCasing="Upper",但是我不太清楚如何做到这一点。
我是否需要使用触发器或以某种方式修改模板?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有效并且似乎是一个合理的解决方案:
确保组合框在加载时不会折叠,否则将找不到模板。
This works and seems like a reasonable solution:
Ensure that the combobox is not collapsed on loaded otherwise the template will not be found.
IMO,更快的方法是将 UpdateTrigger 设置为 PropertyChanged,并在数据对象中,更新时将值大写。
IMO, the quicker way is to set the UpdateTrigger to PropertyChanged and, in the data object, uppercase the value when it is updated.
我发现使用附加属性的 post 。这允许将其用于所有 ComboBox,而无需重写代码。
I found that post where the attached property is used. That permit to use that for all of your ComboBox without rewriting the code.
或者尝试创建一个附加文本框的行为
or try creating an attached behaviour for the textbox