Archive for May, 2009

DNUG Meeting: The Zen of Inversion of Control

Friday, May 15th, 2009
Photo of Christopher Fairbairn
Date: Wednesday May 20th 2009
Time: Gather at 5:30 pm, starting at 6:00 pm
Location: Canterbury Innovation Incubator
Presenter: Christopher Fairbairn

Heard of the concepts Inversion of Control and Dependency Injection, but not quite sure what they are or how they can be applied to your day to day coding? Then this demo filled presentation is for you!

Learn from one beginner’s journey to better understand the fundamentals, without feeling the need for a dictionary to translate all the foreign terms and concepts that inevitably come about.

And even if you’re a Dependency Injection guru, you may learn a little background knowledge of new languages features introduced in C# 2.0 and C# 3.0 that make things easier to implement.

Making auto suggestions more appropriate for your textbox

Friday, May 1st, 2009

Screenshot showing the textbox providing a list of suggested phone numbersTo 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.

Sample Application

[InputContextSendSMS.zip - 10.8KB]

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.