A nice trick in Windows Phone 7 is that you can choose a different on-screen keyboard layout depending upon your needs. The way you do this is by specifying an InputScope value for the TextBox control. But, how do you know which value to use? The names are helpful, but it is still difficult to tell which one you need. For example, should you use “Digits” or “Number” for an input? I have just the thing to help you. By writing an application that shows every InputScopeNameValue in action, we’ve been able to compile a table of what each layout looks like.

To do this, I made a simple application. I created a ListBox control with a data template that had a TextBlock and a TextBox. The TextBlock’s contents and the TextBox’s InputScope value were both bound to a variable. Then, in the screen’s constructor, I enumerated the names in the InputScopeNameValue enum and made a list of the names. The code to do that enumeration was provided by Chris Eargle. I was joking with him that the method to enumerated an enum was left out of the Compact Framework, and a few minutes later he had some workaround code.

There are several things to keep in mind about the table:

  • The layouts are always subject to change; layouts that are the same today may be different tomorrow when updates for the phone arrive. Make sure that you use the right one for the job even if they appear interchangeable.
  • The table shows appearance but not functionality. It is possible that some layouts with the same appearance have differences in functionality.
  • Some layouts look nearly identical except for minor differences. For example, one layout has a different “Return” key that makes it clear that pushing it “takes an action” instead of entering a new line character.

Here is the snippet of XAML I used to get the ListBox on the screen:

<ListBox Height="595" HorizontalAlignment="Left" Margin="6,6,0,0" Name="inputScopeItems" VerticalAlignment="Top" Width="444">

<ListBox.ItemTemplate>

<DataTemplate>

<StackPanel>

<TextBlock Text="{Binding Path=InputScopeName}" />

<TextBox InputScope="{Binding Path=InputScopeName}" Width="200" />

</StackPanel>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>

This is the code within the code behind file to fill the ListBox:

private void loadInputScopeItems()

{

var scopeNames = from item in typeof(InputScopeNameValue).GetEnumValues()

orderby item

select new InputScopeItem { InputScopeName = item };

inputScopeItems.ItemsSource = scopeNames;

}

Here is the extension method to the Type class that Chris gave me to allow the enumeration:

public static IEnumerable<string> GetEnumValues(this Type type)

{

if (!type.IsEnum)

{

yield break;

}

var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo field in fields)

{

yield return field.Name;

}

}

Running this application in the emulator let me put together this chart showing what each InputScope looks like on screen.

AddressCity, AddressCountryName, AddressCountryShortName, AddressStateOrProvince, Date, DateDayName, DateMonthName, PersonalFullName, PersonalGivenName, PersonalMiddleName, PersonalNamePrefix, PersonalNameSuffix, PersonalSurname, Text

AddressStreet, CurrencyAmount, CurrencyAmountAndSymbol, DateDay, DateMonth, DateYear, Digits, Number, PostalAddress, PostalCode, Time, TimeHour, TimeMinorSec

AlphanumericFullWidth, AlphanumericHalfWidth, Bopomofo, CurrencyChinese, Default, EnumString, FileName, FullFilePath, Hanja, Hiragana, KatakanaFullWidth, KatakanaHalfWidth, LogOnName, NumberFullWidth, OneChar, Password, PhraseList, Private, RegularExpression, Srgs, Xml, Yomi

ApplicationEnd, Maps, Search (Note: This layout differs from the previous layout only in the presentation of the “Return” button in the bottom right corner.)

Chat (Note: The main feature of this layout is the emoticon button in the bottom left, which brings up a choice of emoticons.)

EmailNameOrAddress, EmailSmtoAddress, EmailUserName, Url

NameOrPhoneNumber (Note: This layout differs from the previous only by the replacement of the “.com” key with a semicolon key.)

TelephoneAreaCode, TelephoneCountryCode, TelephoneLocalNumber, TelephoneNumber

Note: This post first published in TechRepublic’s Smartphones blog.