[UWP] While typing "6" in french keyboard it enters like "-6" in UWP Platforms

Hemalatha Marikumar 36 Reputation points
2020-06-02T04:20:44.26+00:00

Hi Team,

I have a sample with entry/ numeric input controls. While changing the keyboard to France, while typing the 6 its turn into -6. Is that known issue? Could you please share any other workaround to resolve the same

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2020-06-02T10:32:23.787+00:00

    Hello,

    Welcome to Microsoft Q&A,

    While typing "6" in french keyboard it enters like "-6" in UWP Platforms

    Derive from official document, it's by-design within UWP input control for no-us keyboard layout. if you want to input number, you could switch to US-keyboard or press Shift + Number. And you could also use the following code the detect which key pressed then convert it to the char.

    private static char? ToChar(VirtualKey key, bool shift)  
    {  
         
        if (32 == (int)key)  
            return ' ';  
      
        VirtualKey search;  
      
       
        foreach (var letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")  
        {  
            if (Enum.TryParse<VirtualKey>(letter.ToString(), out search) && search.Equals(key))  
                return (shift) ? letter : letter.ToString().ToLower()[0];  
        }  
      
       
        foreach (var number in "1234567890")  
        {  
            if (Enum.TryParse<VirtualKey>("Number" + number.ToString(), out search) && search.Equals(key))  
                return number;  
        }  
      
        
        return null;  
    }  
    

    Usage

    private void MyTextBox_KeyDown(object sender, KeyRoutedEventArgs e)  
    {  
        var c = ToChar(e.Key, false);  
    }  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful