Microsoft Excel decimal key behavior in WPF

At Reasult we develop financial forecasting software for the Real Estate sector. We have to deal with a lof of numeric input values in our WPF applications.

Al lot of our customers are used to work with Microsoft Excel. When in Excel the decimal key on the numeric keyboard is pressed always the decimal separator specfied in the regional settings is used. This is not the way a normal Windows (WPF) application handles this key.

With the following piece of code you get the same behavior as Excel.

    public class DecimalKeyTextBox : TextBox
    {
        protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Decimal)
            {
                e.Handled = true;

                string decimalSeparator = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, this, decimalSeparator));
            }

            base.OnKeyDown(e);
        }
    }

Whenever the decimal key on the numeric keyboard is pressed the event is cancelled and the decimal separator specified in the regional settings is used.