WPF:带有强制大写的组合框?
我不知道为什么,但没有一个解决方案对我来说可以正常工作 类似问题。
我意识到 TextBox
有一个属性 (CharacterCasing
),可以将其设置为 Upper
以将任何小写输入更改为大写。它工作得非常好,因为用户在打字时永远不会被打断,大写锁定和移位不会对其产生负面影响,并且其他非字母字符也不会受到负面影响。
问题是没有选项可以将此属性用于 ComboBox。类似帖子中的解决方案似乎对我不起作用。我正在寻找复制 CharacterCasing 属性,但用于 ComboBox。我不介意它成为附属财产,事实上,那太好了。我直接在 xaml 对象上尝试了几个不同的事件,但没有成功。
I'm not sure why, but none of the solutions are working properly for me from a similar question.
I realize that a TextBox
has a property (CharacterCasing
) which can be set to Upper
to change any lowercase typing into uppercase. It works so great because the user is never interrupted while typing, caps lock and shift don't affect it negatively, and other non-alpha characters aren't affected negatively either.
The problem is that there is no option to use this property for a ComboBox. The solutions from that similar posting don't seem to work for me. I'm looking to duplicate the CharacterCasing property but for a ComboBox. I don't mind it being an attached property, in fact, that'd be great. I tried a couple of different events directly on the xaml object, with no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
IsEditable
为 true 时,ComboBox
模板使用TextBox
。因此,您可以替换模板以在TextBox
上设置CharacterCasing
,或者创建一个附加属性,通过名称查找TextBox
(“ PART_EditableTextBox") 并为其设置CharacterCasing
属性。这是附加属性解决方案的简单实现:
以下是如何使用它:
The
ComboBox
template uses aTextBox
whenIsEditable
is true. So you can either replace the template to setCharacterCasing
on theTextBox
, or create an attached property that will find theTextBox
by its name ("PART_EditableTextBox") and set theCharacterCasing
property on it.Here's a simple implementation of the attached property solution:
And here's how to use it: