Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically capitalize all input in WPF

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

like image 565
a_hardin Avatar asked May 07 '09 18:05

a_hardin


3 Answers

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> 
like image 139
Josh G Avatar answered Oct 05 '22 21:10

Josh G


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"/> 
like image 22
vahlala Avatar answered Oct 05 '22 22:10

vahlala


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);
  }
}
like image 33
Lucas B Avatar answered Oct 05 '22 23:10

Lucas B