Search code examples
uwpkeypress

WIndows 10 UWP - How can I determine if a Key press is a letter or number?


Windows 10 UWP: Example: On UWP grid, a button1.content = 1 and a textbox. Using mouse to press button1.content, 1 is shown in the textbox.text. How to simulate numeric keypad (1) and 1 is shown in the textbox.text?


Solution

  • You can use TextBlock.Text to set the text to TextBlock.

    If you want to know the key press, you should add KeyDown in Grid

    <Grid KeyDown="Grid_OnKeyDown"></Grid>
    

    And add the following code

    private void Grid_OnKeyDown(object sender, KeyEventArgs e)
    {
        var str = e.Key.ToString();
        if (char.IsDigit(str[0]))
        {
            //is digit
        }
        // is letter
    }
    

    You can use TextBlock.Text = xx to set the TextBlock.