Automatically capitalize all input in WPF

て烟熏妆下的殇ゞ 提交于 2019-12-01 13:44:28

问题


Is there a way to automatically capitalize all input thoughtout a WPF app?


回答1:


You can case all input into TextBox controls with the following property:

CharacterCasing="Upper"

To apply to all TextBox controls in the entire application create a style for all TextBox controls:

<Style TargetType="{x:Type TextBox}">
    <Setter Property="CharacterCasing" Value="Upper"/>
</Style>



回答2:


I recommend creating a custom Textbox class and override an event to automatically capitalize the text. First, this depends on if you want the text to be capitalize as they type or after input is finished.

E.g. for after input is finished

public class AutoCapizalizeTextBox: TextBox
{
  public AutoCapitalizeTextBox()
  {
  }

  public AutoCapitlizeTextBox()
  {
  }

  protected override void OnLostFocus(EventArgs e)
  {
    this.Text = this.Text.ToUpper();

    base.OnLostFocus(e);
  }
}



回答3:


I don't know if this'll help, it capitalizes all the first letters in the sentence.

http://www.mardymonkey.co.uk/blog/auto-capitalise-a-text-control-in-wpf/




回答4:


If you want to capitalize the input for a single TextBox rather than all TextBoxes like above, you can use the following:

<TextBox CharacterCasing="Upper"/>


来源:https://stackoverflow.com/questions/836162/automatically-capitalize-all-input-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!