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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Like it? Share it!

3 Comments so far. Feel free to join this conversation.

  1. pjulien September 22, 2010 at 10:47 pm - Reply

    How do you detect when somebody has pressed the url arrow in the url keyboard type?

    I don’t see any events on the InputScope

Leave A Response