Windows Phone 7 extended Textbox Control is a digital input text box

Source: Internet
Author: User

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
}
}

}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.