Create WPF TextBox that accepts only numbers [duplicate]

Most implementations I have seen so far are using the PreviewTextInput event to implement the correct mask behavior. This one inherits from TextBox and this one uses attached properties. Both use .Net’s MaskedTextProvider to provide the correct mask behaviour, but if you just want a simple ‘numbers only’ textbox you don’t need this class.

Leave a Comment