Key char on Windows Phone

2019-03-01 00:49发布

问题:

I want to determine the symbol that user entered by keypad. For example in Windows Forms KeyPressEventArgs has KeyChar property, but there is no this property for KeyEventArgs in Windows Phone.

It's needed to handle this event, because i want to handle some cyrillic symbols.

回答1:

As you have said e.Key and e.PlatformKeyCode don't grant success - e.Key = Key.Unknown.
But I think you can try to do like this:

private void myTextbox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
   char added = myTextbox.Text.ElementAt(myTextbox.Text.Length - 1);
}

When the users enters symbol - check the last added to text, as I've checked it works with cyrillic. Then in the same event you can do what you want with this text or symbol.
I've checked this on TextBox thought I don't know if your problem is concerned with it.



回答2:

You can use the Key property from the event args:

if(e.Key == Key.Enter) { }