To round out my coverage of Input Contexts we need to cover the concept of Input Classes. Put simply an input class is a hint to the Windows Mobile OS as to what kind of information should be entered into a text box (for example an email address, phone number, or person’s name).
Selecting an Input Class for a textbox will change the source of data used for the auto suggestions provided by the OS as the user starts typing. For example in the screenshot above you can see the user is typing in a person’s name yet the operating system is suggesting matching cellphone numbers.
To specify the Input Class for a textbox we can use the native SHSetInputContext API and set the SHIC_FEATURE_CLASS feature. Yesterday’s code sample provided a suitable wrapper around this API for this purpose.
To demonstrate the use of Input Contexts I decided to make a modified version of the SendSMS application I presented earlier. In this modified version when a user starts to type in a person’s name into the phone number textbox the operating system will provide suggested phone numbers based upon data found within Pocket Outlook’s contacts list.
The code changes required to the original sample application were minimal and consisted of the following two lines of code which use the InputClass developed yesterday.
// Setup the input context for the phone number text box // so that it will provide auto suggestions of phone numbers // associated with outlook/SIM contacts. InputContext.SetClass(txtPhoneNumber, InputContextClass.Phone); InputContext.SetHaveTrailer(txtPhoneNumber, false);
The call to SetHaveTrailer means that if the user selects a suggestion from the popup list the OS will not automatically insert a seperator character. If you set this feature to true a semicolon would be inserted allowing the user to quickly create a list of two or more recipients.