Windows Phone Virtual Keyboards
Windows Phone 7 comes with about 57 different input scopes you can use (there’s actually 62 or so, but 5 of them give an exception when loaded). The two most important scopes are Text and TelephoneNumber.
- TelephoneNumber gives you the numeric keypad when the user goes to enter text.
- Text gives you word suggestions and smiley faces like in messaging.
Setting these in code is a little convoluted. It’s a lot easier to simply set it in the XAML, eg:
<TextBox … .. InputScope="Text" ></TextBox>
If you want to set the input scope in code, you need to construct an InputScope class instance, and add to it a InputScopeName class with the InputScopeName’s Value set to the InputScopeNameValue enum value. It’s easiest to wrap this in an extension method:
<Extension()>
Sub SetInputScope(ByVal textbox As TextBox, ByVal value As InputScopeNameValue)
Dim scope As New InputScope
scope.Names.Add(New InputScopeName With {.NameValue = value})
textbox.InputScope = scope
End Sub
Then setting the input scope in code simply becomes:
TextBox1.SetInputScope(InputScopeNameValue.Text)
Some things to note about input scopes:
- although you can cache an input scope, and assign it to a different textbox on an as needed basis, you have to be careful to ensure it is only assigned to one textbox at any given time. I doubt the memory minimization would be worth the effort.
- an InputScope can have multiple InputScopeName values, but it seems like only the first one in the list is used.
- the following InputScopeNameValue’s give a runtime error when run from the debugger: PhraseList, RegularExpression
, Srgs , Xml , EnumString
The main values you’ll want to use are:
value |
description |
Default |
Standard QWERTY layout |
Text |
Standard layout with features such as autocorrect and text suggestion |
Url |
Standard layout with .com and customized Enter key for typing URLs. |
EmailSmtpAddress |
Standard layout with .com and @ key. |
EmailNameOrAddress |
Standard layout with .com and @ key, and easy access to phone number layout. |
Maps |
Standard layout with a customized Enter key. Used to type a location to search for on a map |
TelephoneNumber |
12-key layout |
Search |
Semi-transparent layout with a Search and .com key. |
NameOrPhoneNumber |
Standard layout with access to phone number layout. Used to type in the SMS To field |
Chat |
Text input that uses intelligent features such as abbreviations |
abbreviated from http://msdn.microsoft.com/en-us/library/39D7932C-3E67-4142-9CCB-68843A571A66(v=vs.95,d=lightweight).aspx