Windows Phone keyboard comma - dot conflict

只愿长相守 提交于 2020-01-16 00:46:44

问题


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



来源:https://stackoverflow.com/questions/17048817/windows-phone-keyboard-comma-dot-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!