How to change the on-screen keyboard input scope for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
When you use controls such as text boxes in your Windows Phone application, the user enters data by using the on-screen keyboard. Depending on the type of data the user is entering, the input scope of default keyboard may not be the best choice. You can change the input scope of the on-screen keyboard to one of many built-in options. When you change the input scope of the keyboard, you can make it much faster and easier for users to enter data in your application.
For screenshots of the different built-in keyboards, see On-screen keyboard input scope index for Windows Phone 8.
To download a sample application that contains all the different keyboard options, see Keyboard Index Sample.
Note
The on-screen keyboard is also referred to as the software-based input panel, or SIP.
This topic contains the following sections.
- Changing the Keyboard Input Scope
- Using IntelliSense to Test the Keyboard Input Scope Options
- Setting the Keyboard Input Scope in Code
- Related Topics
Changing the Keyboard Input Scope
You change the input scope by specifying the one you want to use for a particular control. To see a list of input scope options, see InputScopeNameValue. In this procedure, you change the input scope of a text box to accept numeric input. This procedure assumes that you have a Windows Phone application that has a page that contains controls.
To change the keyboard input scope
In the XAML file for your page, locate the tag for the control that you want to change. For example, your control’s tag might look like the following:
<TextBox Name="txtPhoneNumber" />
Add the InputScope attribute to the tag and specify the value that you want. For example, to specify numeric input, your result should look like the following:
<TextBox InputScope="Number" Name="txtPhoneNumber" />
Using IntelliSense to Test the Keyboard Input Scope Options
You can use IntelliSense to get the name of the input scope that you want to use. In this procedure, you add a new text box to test the different input scope options. This procedure assumes that you have a Windows Phone application that has a page that you can add a control to.
To test the keyboard input scope options
In the XAML file for your page, add the following code:
<TextBox Name="txtPhoneNumber" > <TextBox.InputScope> <InputScope> <InputScopeName NameValue="Number" /> </InputScope> </TextBox.InputScope> </TextBox>
Place the cursor between the quotation marks after NameValue and press the space key.
IntelliSense lists the input scope options.
Select an option to test.
Run your application and click in the text box to see the on-screen keyboard.
Repeat steps 2 through 4 to test the different input scope options
Setting the Keyboard Input Scope in Code
You can also set the keyboard input scope by using code. This procedure assumes that you have a Windows Phone application that has a page that you can add a control to.
To set the keyboard input scope in code
In the XAML file for your page, add the following code:
<TextBox Name="txtPhoneNumber" />
In the code-behind file for your page, in the constructor, after any existing code, add the following code:
InputScope scope = new InputScope(); InputScopeName name = new InputScopeName(); name.NameValue = InputScopeNameValue.Number; scope.Names.Add(name); txtPhoneNumber.InputScope = scope;
Dim scope As New InputScope Dim name As New InputScopeName name.NameValue = InputScopeNameValue.Number scope.Names.Add(name) txtPhoneNumber.InputScope = scope