Ecco un campione per verificare se un tasto premuto è adatto per un numero di telefono (cifre, spazi, punti e +):
using Windows.System;
...
bool isDigitKey(VirtualKey keyValue)
{
return ((keyValue >= VirtualKey.Number0 && keyValue <= VirtualKey.Number9)||
(keyValue >= VirtualKey.NumberPad0 && keyValue <= VirtualKey.NumberPad9));
}
private void TextBoxTo_KeyDown(object sender, KeyRoutedEventArgs e)
{
// Characters for phone numbers (+, ., space, digits)
Boolean isCharFiltered = !isDigitKey(e.Key) && // Digits
(e.Key != VirtualKey.Space) && // Space
(e.Key != VirtualKey.Add) && // + on NumPad
((int)e.Key != 0xbb) && // + which is not correctly mapped to VirualKey.Add
(e.Key != VirtualKey.Decimal) && // . on NumPad
((int)e.Key != 0xbe); // . which is curiously mapped to Shift
// Unfortunately, we can't filter à, é and è on a french keyboard because these keys are mapped to Number0, Number2 and Number7
e.Handled = isCharFiltered;
}
Siete alla ricerca di 'KeyRoutedEventArgs.Key'? – shahkalpesh
Fai attenzione, le app di Windows Store sono distribuite in tutto il mondo. In particolare, gli utenti in Asia hanno opinioni inusuali su come appaiono i numeri e le lettere. –