I have a TextBox which I'm using to handle numbers. I therefore only accept [0-9.,]. However, "." is the only valid decimal separator. I therefore only want this in my text, but I want to accept "," too, and swap it with a "." such that the displayed character is a valid one.
So - how do I swap an input character? I'm assuming I can fetch this and swap it in some input event? Or do I have to replace it after it has been inserted into the TextBox?
I tried swapping it in the OnPreviewKeyDown and OnPreviewTextInput events, but the properties holding the input characters are read only. I'd like to do something like this:
protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.OemComma)
{
e.Key = Key.OemPeriod;
}
base.OnPreviewKeyDown(e);
}