On other platforms, whether it is winform, WPF, Silverlight, or ASP. NET, you may encounter the following requirement: You can only enter numbers in the input box. In fact, the implementation methods are similar. Obtain the key of the input text and determine whether it is a usable range. The following describes how to allow the input box to only enter numbers in Windows Phone.
We know that we can set the inputscope in the input box. When the input box gets the focus, different SIP messages are displayed. In wnidows phone, there are two inputscope types that can pop up the sip of the input number:
Number and telephonenumber:
The keys corresponding to the numbers in the two types of SIP are also different:
The 0-9 platformkeycode of inputscope is 48-57 (hexadecimal is 0x30-0x39), and the key is the D0-D9;
Inputscope is telephonenumber 0-9 platformkeycode is 96-105 (hexadecimal is 0x60-0x69), key is NumPad0-NumPad9.
Note that in the SIP with inputscope as number, @ and 2, # And 3, $ and 4...) and 9 share a key.Therefore, we do not recommend that you use the sip with inputscope as the number-only inputscope.
Summary: in Windows Phone, you can only enter numbers in the input box:
1. Set inputscope in the input box to telephonenumber.
2. register the keydown event in the input box and make the above judgment in the event
Source codeDownload:
Update: InIn mango, The inputscope of number is added. Set inputscope to number.