Silverlight 5–Combo box type ahead

A nice, small feature in the new Silverlight 5 Beta is the ability toCombobox type ahead in combo boxes.

This makes choosing from long list far simpler.

You can see this at work by whipping up a very quick Silverlight 5 application.

On the Main page add a combo box,

 

<Grid
   x:Name="LayoutRoot"
   Background="White">
   <ComboBox
      x:Name="theComboBox"
      Height="40"
      Width="150"
      Margin="20" />
</Grid>

In the code behind we’ll create some data to act as the ItemsDataSource for the combo box:

public MainPage( )
{
   InitializeComponent( );
   List<string> contents = new List<string>
   { "apples",
      "berries",
      "apple pie",
      "apple strudel",
      "blueberries",
      "strawberries",
      "cherries",
      "cherry pie",
      "bananas"};
   theComboBox.ItemsSource = contents;
}

That’s enough to see the effect.  When you run the program the combo box comes up empty. Start typing apple strudel and you’ll see that the combo box first finds apples, then apple pie (on the space) and then when you type the s, it finds apple strudel. 

You can see this most clearly by rerunning the application and opening the combo box before you begin typing. You can then see the selected item move as you type (see image at top).  Nice.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Data, Essentials, Silverlight 5 and tagged . Bookmark the permalink.

9 Responses to Silverlight 5–Combo box type ahead

Comments are closed.