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.

Share

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been 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 Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.
This entry was posted in Data, Essentials, Silverlight 5 and tagged . Bookmark the permalink.

9 Responses to Silverlight 5–Combo box type ahead

  1. Beatris says:

    Great post. I was checking continuously this blog and I’m impressed!
    Very useful info specially the last part 🙂 I care for such information a lot.
    I was looking for this particular info for a long time.
    Thank you and good luck.

  2. Tom Matt says:

    First of all , thanks for the above article..
    Would you be kindly confirm whether ,Type Ahead feature of combo box in Silverlight 5 will be affected by adding a seperate theme to the Xaml ? i have made an app with combobox- n listbox -s and the Type ahed feature is working fine. i created a fresh versio of that app with Windows7 Theme in it and the feature is dead. can select values pressing keywords.
    I used WCF-RIA and i cant think of any other change ,other than the theme, from my original version. any idea?
    Thx in advance

  3. Jon says:

    I find it incredibly lame that the IsEditable property from WPF is missing from ComboBox in Silverlight. I really have to wonder what is going on with Silverlight and WPF and if Microsoft is going to just let them die. For example, you don’t see much activity going on on the Silverlight and WPF Toolkit web sites. I think it’s stupid that they have wasted time making chart controls and other less important controls when they don’t even have the basics working like an editable combobox. Also, I really wish they would fix something things in WPF, like add a DataPager control and a PagedCollectionView class. Also, they need a VirtualizingWrapPanel for making Explorer-like applications. I think Microsoft has dropped the ball on WPF and Silverlight. It will be fun programming in JavaScript in the coming years. NOT!

    • I’m a bit taken aback by the intensity of your comment. “lame, stupid…” seem pretty strong words for a dev. framework that, I take it, you like.

      Tradeoffs have certainly been made, but given that Silverlight was in beta 4 years ago, and is already at version 5, with significant improvements at each version, I think its doing pretty well.

      I will pass your comments along to the team, but I do think you may want to have a glass of tea and take a deep breath 🙂

      -Jesse

  4. Chris says:

    The “autocomplete” or “type ahead” feature would be considerably nicer and more useful if support for and “autocomplete callback” were provided that allowed the a delegate to be supplied that would be invoked by the combo whenever the user typed a key. Implementing a combo box that behaves appropriately in such a scenario in grunge work that *should* be implemented by the framework. It is obviously a very common need and why a built-in mechanism for autocomplete callbacks isn’t provided OOTB is a mystery to me.

    • Matthew MacDonald says:

      If you need anything more than the very basic (but convenient) type ahead feature, use Silverlight’s AutoCompleteBox instead. It lets you filter with a callback.

  5. CarlD says:

    Isn’t this feature normally called “Incremental Search”? Type-ahead has a different (and largely obsolete) meaning in my experience-based computer-terms dictionary.

Leave a Reply

Your email address will not be published.