If you write applications for Silverlight for Windows Phone, one of the features you quickly become familiar with is the Software Input Panel, or SIP. The SIP is the virtual keyboard that appears when a text-input control such as a TextBox gets the input focus. You don’t have to do anything to make the SIP appear; that happens automatically. But you can lend Silverlight a hand by specifying an input scope for each text-input control that you create. This enables the runtime to stylize the SIP to match the type of data you expect the user to enter.

You specify an input scope on a per-control basis by assigning a value to the control’s InputScope property. To demonstrate, I created a new Silverlight for Windows Phone project and added the following TextBlock and TextBox declarations to a vertical StackPanel in MainPage.xaml:

<TextBlock Text="Name" Margin="12,0,0,0" Style="{StaticResource PhoneTextNormalStyle}" />

<TextBox InputScope="Default" Style="{StaticResource PhoneTextBoxStyle}" />

 

<TextBlock Text="E-Mail Address" Margin="12,0,0,0" Style="{StaticResource PhoneTextNormalStyle}" />

<TextBox InputScope="EmailSmtpAddress" Style="{StaticResource PhoneTextBoxStyle}" />

 

<TextBlock Text="Phone Number" Margin="12,0,0,0" Style="{StaticResource PhoneTextNormalStyle}" />

<TextBox InputScope="TelephoneNumber" Style="{StaticResource PhoneTextBoxStyle}" />

 

<TextBlock Text="Blog Url" Margin="12,0,0,0" Style="{StaticResource PhoneTextNormalStyle}" />

<TextBox InputScope="Url" Style="{StaticResource PhoneTextBoxStyle}" />

When you run the application and the "Name" box has the focus, the UI looks like this:

Default InputScope

When the "E-Mail Address" box has the focus, the SIP changes slightly to include "@" and ".com" keys:

E-Mail InputScope

And when the "Phone Number" box has the focus, the SIP morphs into a telephone keypad:

Telephone InputScope 

SIPs differ not only in appearance but in behavior. For example, the Default SIP does little in the way of helping the user enter text. But setting InputScope to "Text" turns on auto-capitalization, auto-completion, and other helpful features.

The current Silverlight for Windows Phone CTP includes more than 60 InputScopes. Some of them, such as Bopomofo and KatakanaHalfWidth, you’ll probably never use. A handful, including Xml and RegularExpression, generate runtime exceptions. (This is, after all, a preview release.) But others, such as Text and TelephoneNumber, are extraordinarily useful and will probably be used by a majority of developers.

You can view a list of InputScopes in IntelliSense if you use the more verbose property-element syntax to specify an InputScope name:

InputScope IntelliSense

You can use reflection to generate a list of InputScopes in code:

List<string> names = new List<string>();

for (int i = -10; i < 100; i++)

{

    if (Enum.IsDefined(typeof(InputScopeNameValue), i))

        names.Add(Enum.GetName(typeof(InputScopeNameValue), i));

}

You can even assign an InputScope to a control programmatically:

MyTextBox.InputScope = new InputScope()

    { Names = { new InputScopeName() { NameValue = "Text" } } };

Using InputScope to produce context-aware SIPs improves the user experience. Use them liberally if you build phone applications that support keyboard data entry!