views:

3049

answers:

4
+3  Q: 

WPF Edit Mask

What is the easiest way to specify an edit mask in WPF for a simple Text Box?

e.g. one that transforms 10000 to 10,000 as you type.

A: 

Easiest and most straightforward way is probably just to grab the TextChanged event and do whatever processing you need.

ex... http://karlhulme.wordpress.com/2007/02/15/masking-input-to-a-wpf-textbox/

routeNpingme
Yes I can do that for now. I was hoping there was a quick and easy template to apply or similar in xaml.
Gus Paul
When you do this kind of solution, please make sure that you accept interim "bad" values. There is nothing more frustrating than going to change 10000 to 20000 by deleting the 1 and having the text box reformat as just "0"
scwagner
+2  A: 

Short answer, there is no easy way. If you use masks quite often, I would recommend creating your own control with masking functionality. Using the MaskedTextProvider class should be fairly straightforward.

See the following for an example of a custom TextBox with masking capabilities:

Masked TextBox example...

Whytespot
A: 

Have you looked at the Xceed DataGrid Express for WPF. It is free and provides a masked text box control that will very simply do what you want.

AndyM
A: 

Have a look at these free wpf controls. There's also a maskedtextbox.

gary72