.net - Swap input character to WPF TextBox before it is added to the Text -
I have a text box that I am using to handle numbers. So I accept only [0- 9.,]. However, "." There is only a valid decimal separator, so I want this only in my text, but I want to accept "," too, and want to swap it with "". "As the displayed character is a legitimate one.
So - how do I swap an input character? I'm assuming that I can bring it and swap it in some input event? Or do I text Change it after putting it in the box?
I tried to swap it in the OnPreviewKeyDown and OnPreviewTextInput events, but the properties containing the input characters are only for reading. I want to do something like this :
protected over Zyde Zero OnPrivacyDown (System.Windows.Epoot.quaEventArguesE) {if (EkeE == key.omcoma) {EK = key OmParod;} Base.OnPreviewKeyDown (e);}
You can use Text Change Event and change the text property every time. / P>
Private Zero Text boxboxext (Object Sender, TextChangedEventArgs E) {Text box box = (Text box) Sender; box. Text = box. Change text (",", "."); }
If you are using binding then you can make a converter that changes after text changes it.
& lt; Text box name = "text box" text = "{binding path = number, converter = decimal converter}" /> Public Class Decimal Converter: Public Object Convert (Object Value, Type Type, Object Parameter, CultureInfo Culture) {Return Value; } Public Object Convertback (type object value, type type, object parameter, culture info culture) {string strValue = (string) value; Return strValue.Replace (",", "."); }}
Comments
Post a Comment