Categories: Blog

Understanding Input Scope in Silverlight for Windows Phone

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:

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

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

 

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:

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!

Jeff Prosise

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

2 weeks ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

3 weeks ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

1 month ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

2 months ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

2 months ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago