Windows Phone development (13): how to regulate user input Behavior

Source: Internet
Author: User

Many times, we impose certain restrictions on user operations or input to avoid unnecessary exceptions or errors. Therefore, for some special types, it is necessary to restrict input.

By changing the display mode of the screen keyboard, You can standardize and tell the user what to enter here.

To do this is not complicated, as long as a class is used, it is enough-inputscope, which has a names attribute, including the inputscopename list, and the namevalue of inputscopename is an enumerated value, the displayed Screen Keyboard depends on the enumerated value.

A lot of content, at least what each enumeration item represents, there is no need to explain them one by one. You can refer to the SDK documentation.

The above is the theoretical part. Is it so God? Let's prove it through practice.

Start your Vs and create a new Silverlight for Windows Phone application project.

The interface is very simple. Just put a few Textbox, and we only need a few typical applications, because the principles are the same. Such as numbers, dates, times, and email addresses.

<Phone: phoneapplicationpage <br/> X: class = "inputscpsample. mainpage "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.micro Soft.com/expression/blend/2008 "<br/> xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "<br/> MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" portrait "orientation =" portra It "<br/> shell: systemtray. isvisible = "true" xmlns: My = "CLR-namespace: system; Assembly = mscorlib"> <br/> <Phone: phoneapplicationpage. resources> <br/> <my: Double X: Key = "fontsize"> 32 </My: Double> <br/> </Phone: phoneapplicationpage. resources> <br/> <! -- Layoutroot is the root mesh that contains all page content --> <br/> <grid X: Name = "layoutroot" background = "Transparent"> <br/> <grid. rowdefinitions> <br/> <rowdefinition Height = "Auto"/> <br/> <rowdefinition Height = "*"/> <br/> </grid. rowdefinitions> </P> <p> <! -- Titlepanel contains the application name and page title --> <br/> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <br/> <textblock X: name = "applicationtitle" text = "my application" style = "{staticresource phonetextnormalstyle}"/> <br/> <textblock X: name = "pagetitle" text = "standard input" margin = "9,-7,0, 0 "style =" {staticresource phonetexttitle1style} "/> <br/> </stackpanel> </P> <p> <! -- Contentpanel-place other content here --> <br/> <scrollviewer X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0 "<br/> horizontalscrollbarvisibility =" Auto "<br/> verticalscrollbarvisibility =" Auto "> <br/> <stackpanel> <br/> <textblock text =" Enter the email address: "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txtemail "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inpu Tscope> <br/> <inputscope. names> <br/> <inputscopename namevalue = "emailnameoraddress"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "input number:" margin =, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txtnumber "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbo X. inputscope> <br/> <inputscope. names> <br/> <inputscopename namevalue = "Number"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "input time:" margin = "0, 15, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txttime "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inputs Usage> <br/> <inputscope. names> <br/> <inputscopename namevalue = "time"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "input RMB:" margin =, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txtrmb "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inputscope> <br/> <Inputscope> <br/> <inputscope. names> <br/> <inputscopename namevalue = "currencychinese"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "Enter the phone number:" margin =, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txtphonenum "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inputscop E> <br/> <inputscope. names> <br/> <inputscopename namevalue = "telephonenumber"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "input URL:" margin = "0, 15, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txturl "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inputsco PE> <br/> <inputscope. names> <br/> <inputscopename namevalue = "url"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> <textblock text = "enter a single character:" margin =, 0, 0 "fontsize =" {staticresource fontsize} "/> <br/> <textbox name =" txtchat "fontsize =" {staticresource fontsize} "horizontalalignment =" stretch "> <br/> <textbox. inputscope> <br/> <Inputscope> <br/> <inputscope. names> <br/> <inputscopename namevalue = "chat"/> <br/> </inputscope. names> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> </P> <p> </stackpanel> <br/> </scrollviewer> <br/> </GRID> </P> <p> <! -- DEMO code of ApplicationBar usage --> <br/> <! -- <Phone: phoneapplicationpage. applicationBar> <br/> <shell: ApplicationBar isvisible = "true" ismenuenabled = "true"> <br/> <shell: applicationbariconbutton iconuri = "/images/appbar_button1.png" text = "button 1"/> <br/> <shell: applicationbariconbutton iconuri = "/images/appbar_button2.png" text = "button 2"/> <br/> <shell: ApplicationBar. menuitems> <br/> <shell: applicationbarmenuitem text = "menu item 1"/> <br/> <shell: applicationbarmenuitem text = "menu item 2"/> <br/> </shell: ApplicationBar. menuitems> <br/> </shell: ApplicationBar> <br/> </Phone: phoneapplicationpage. applicationBar> --> </P> <p> </Phone: phoneapplicationpage>

Of course, this restriction is not very accurate, so you should verify the specific data type more than once during validation in your application.

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.