Windows Phone keyboard comma - dot conflict

2019-07-29 22:20发布

问题:

I would like to use Numeric keyboard (InputScope=Number) but want to display ',' instead of '.' on the lower-left hand corner because it is the decimal separator in Turkish language. The keyboard layout appears depending on the phone language even if I force the Culture in code like this: System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("tr-TR"); System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("tr-TR");

How can I force numeric keyboard with only ',' on the lower-left hand corner?

Or at least how can I detect the difference between the two characters on KeyEventArgs? Because both returns Unknown as Key code (well obviously same key) and I cannot come up with a way to differentiate them when user presses?

回答1:

Given that you can't change the culture for the Keyboard you have two options:

  1. Hook KeyUp and if the KeyCode is unknown then you're getting either the . or ,
  2. Hook TextChanged and check the last letter to see if it is a . or , and replace as needed (note that you're going to retrigger TextChanged if you update the text in TextChanged)

For example:

    private void txt_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
        if (e.Key == System.Windows.Input.Key.Unknown)
        {
            txt.Text = txt.Text.Replace('.', ',');

            // reset cursor position to the end of the text (replacing the text will place
            // the cursor at the start)
            txt.Select(txt.Text.Length, 0);
        }
    } 


回答2:

This is actually a setting of the phone itself. When the region is set to a region that has comma decimal separator and the keyboard, it will display the comma. See the following screenshot with French region and French keyboard