Some information is input, such as phone numbers and zip codes. However, the control in Windows Phone 7 does not only allow the input of numbers, to implement such a control, you can only manually extend the Textbox Control.
To expand a widget:
1. Define a class. This class must inherit the class of the control you want to extend.
For example
Public class numerictextbox: textbox
2. Add a spatial reference to the class of the extended control on the page.
For example
Xmlns: My = "CLR-namespace: wpnumerictextbox. Controls"
3. Call controls
For example
<My: numerictextbox X: Name = "numtbx"/>
The following is an example of the numeric input text box control:
Controls
Numerictextbox. CS
Using System;
Using System. Windows. controls;
Using System. Windows. input;
Namespace Wpnumerictextbox. Controls
{
Public Class Numerictextbox: textbox
{
// Return key and number key
Private Readonly Key [] numeric = New Key [] {key. Back, key. numpad0, key. numpad1, key. numpad2, key. numpad3, key. numpad4,
Key. numpad5, key. numpad6, key. numpad7, key. numpad8, key. numpad9 };
Public Numerictextbox ()
{
// Set text to phone number text input mode
This . Inputscope = New Inputscope ();
This . Inputscope. Names. Add ( New Inputscopename () {namevalue = Inputscopenamevalue. telephonenumber });
}
Protected Override Void Onkeydown (keyeventargs E)
{ // Set E. Handled = true if it is a numeric or return key, indicating that the event has been processed.
If (Array. indexof (numeric, E. Key) = - 1 )
{
E. Handled = True ;
}
Base . Onkeydown (E ); // Important, if not called the back button is not handled
}
}
}