Nasenbaer
Nasenbaer

Reputation: 4900

Only allow special characters in Textbox when pressing keys on keyboard

I need a textbox where the user only can work with uppercase characters. Also some special characters like - _ and <.

I wonder if there could be a ways to catch the PreviewKeyDown or KeyDown Event to convert the pressed keys to UpperCase.

MyTextBox1 > System.Windows.Input.KeyEventArgs > Key is ReadOnly.

Any idea how that can be managed?

Upvotes: 0

Views: 1035

Answers (1)

Ray
Ray

Reputation: 46555

You don't need to do that, you can just use the CharacterCasing property

<TextBox CharacterCasing="Upper" />

Other than that if you need a more general answer, look at my answer to How do I get a TextBox to only accept numeric input in WPF? here

Upvotes: 3

Related Questions