Changing the Numeric Keypad Period to a Comma

For some users, their Region and Language settings define a Currency formatting that uses commas as the decimal separator. Users who prefer using the numeric keypad may find the lack of a comma on the numeric keypad problematic. Many programs, such as Excel, can handle using the period as the decimal separator even if the localization settings specify the comma. However LightSwitch’s Money Editor control doesn’t seem to handle this.

An ugly fix, but one that seems to work, is to handle the KeyDown event for the currency TextBox and manually swap the numeric keypad period for a comma.

Add the following usings to your screen’s code:

using System.Windows.Input; 
using System.Windows.Controls;

Then in the Created method for the screen, add something like this:

this.FindControl("MyCurrencyControl").ControlAvailable += 
  (s, e) => (e.Control as Control).KeyDown += MyScreen_KeyDown;

and then this method:

void MyScreen_KeyDown(object sender, KeyEventArgs e)
  if (e.Key == Key.Decimal)
    var textBox = sender as TextBox;
    string text = textBox.Text;
    int start = textBox.SelectionStart;
    textBox.Text = text.Substring(0, start) 
      + "," + text.Substring(start + textBox.SelectionLength);
    textBox.SelectionStart = start + 1;
    e.Handled = true;