Previous month:
December 2010
Next month:
February 2011

January 2011

AutoComplete TextBox with WPF

Often I’m asked for a TextBox with automatic completion. There’s already one available with WPF. TextBox is just the wrong place to look at. It’s a ComboBox with the help of the TextSearch class. This blog entry gives you information on how this can be done.

The following ComboBox binds to  collection of the type Racer. This type contains properties Firstname and Lastname. Using the attached property TextSearch.TextPath enables auto completion. The property TextPath is set to the property of the collection that is used by search. As the user enters text in the ComboBox, the selected item moves immediately to the first matching item.

<ComboBox VerticalContentAlignment="Center" HorizontalContentAlignment="Center" TextSearch.TextPath="Firstname" Width="200" Height="100" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" > <TextBlock.Text> <MultiBinding StringFormat="{}{0} {1}"> <Binding Path="Firstname" /> <Binding Path="Lastname" /> </MultiBinding> </TextBlock.Text> </TextBlock> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>
How does this work? As the user enters text in a ComboBox, the Text property is set. With text input the protected method OnTextInput of the base class ItemsControl is invoked. This method checks for a TextSearch object and invokes the DoSearch method. So the ItemsControl and TextSearch are connected.

In case the user should be allowed to enter some data that is not in the bound list, the ComboBox property IsEditable can be set to true. Instead of using the SelectedItem in that case, the Text property of the ComboBox returns the text that is entered by the user. This sample binds to a collection of strings, setting the property TextPath to an empty string autocompletes to a string from the bound list. The user is also allowed to enter text not bound.

<ComboBox VerticalContentAlignment="Center" HorizontalContentAlignment="Center" TextSearch.TextPath="" Width="200" Height="100" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" IsEditable="True"> </ComboBox>

More information on WPF in my WPF workshop.


CN innovation

Welcome 2011

2010 has been a great year with Microsoft products such as Windows Phone 7, Kinect, Visual Studio 2010…  As the new year started, what can be expected from 2011?

During the MIX 2011 conference I’m expecting a Beta of Silverlight 5. Cool new features of this new version were already announced at the Silverlight Firestarter event.

More and more Windows Azure features are coming during 2011 as was already announced at PDC 2010. Microsoft not only has a good story on platform as a service, but also software as a service – Office 365 is coming! I’m already a happy user of BPOS.

I’m also expecting an minor update for Windows Phone 7 in the next few months. Copy and paste was already mentioned with this update, I’m also expecting features such as using a custom ringtone…

I think PDC 2011 will be much bigger than the PDC from 2010. What do I expect there? Windows 7 was a minor release (Windows 6.1) with fixes on Windows Vista (Windows 6.0) and new UI features. Probably Windows 8 will be a major release with big changes. What about HTML 5 integration? Much more use of the cloud? At PDC 2011 probably we will hear exciting news on the next version of the operating system. What about the HTML 5 developer story? I think Microsoft will deliver a product for this technology. Web Matrix and ASP.NET MVC is only part of the story. Visual Studio

What about Microsoft’s iPad? Really, Microsoft was very early with touch-products. I’m owning a Ultra Mobile PC (Samsung Q1) that was available with Windows XP. Most times I’ve used this touch-device without a keyboard. Handwriting recognition was really great. I’ve used this device not only for browsing the Web but also writing emails. I’m using Tablet PC’s since several editions of Fujitsu Lifebook T Series. A problem the UMPC had was the price. The iPad demonstrated this can be changed. In 2011 I’m expecting to hear Microsoft’s answer to the iPad.

2011 is an exciting year to come. My big focus will be on Silverlight, Windows Azure, and HTML 5 across different platforms.

What is your expectation of 2011?


CN innovation

follow me at twitter