Using Input Scope in Windows Phone 7
When the user places the focus on to the textbox, in the Windows Phone 7 , the default keyboard / onscreen keyboard will pop up for the user to touch and type the characters to the textbox.
It is also important that the keyboard can be customized depending on the input the user will be typing or the data type the textbox is associated with.
For example, user may want only numeric fields and some symbols when typing the Phone numbers or text with symbols like (@,.) when entering a email ID .
As a developer, we are not just limited to the Default keyboard layout. We can specify the input scope, which determines the layout of the Keyboard that is used in Software Input panel. This will help the end user to easily type the required characters even faster.
Setting the Input Scope is very simple and is demonstrated below.The sample Application contains a simple textbox (textBox1) with a title.
When the focus comes to the textbox, the default onscreen keyboard will be displayed as shown in the screenshot below.
It’s time to change the input scope now. In the PhoneApplicationPage_Loaded Event of the Form, I use the following code snippet .
InputScope Keyboard = new InputScope(); InputScopeName ScopeName = new InputScopeName(); ScopeName.NameValue = InputScopeNameValue.Digits; Keyboard.Names.Add(ScopeName); textBox1.InputScope = Keyboard;
When I run the Application now and the textbox is focused, the Keyboard layout is changed to support digits.
To change the onscreen keyboard to support Url, Change the NameValue to InputScopeNameValue.Url .
ScopeName.NameValue = InputScopeNameValue.Url;
To change the onscreen keyboard to support Url, Change the NameValue to InputScopeNameValue.EmailSmtpAddress.
ScopeName.NameValue = InputScopeNameValue.EmailSmtpAddress;
The Input Scope and InputScopeName Class is part of the PresentationCore.dll Assembly and is found in the namespace System.Windows.Input