AutoCompleteBox – SelectedItem design change – source code download
One piece of feedback that has been recently made clear is that of the community on the AutoCompleteBox’s SelectedItem property. Thanks for letting us know that this is important. In this post, I’m providing a fix for this new, and admittedly better, behavior.
The request started on the Silverlight.net forums and then was opened up as a feature request on the CodePlex issue tracker for the toolkit. This is the ideal feedback mechanism since it is easy to track, visible, and the voting mechanism really helps us prioritize our team’s work. We actually even synchronize our internal TFS bug database with the CodePlex work items, so it’s pretty slick.
As released in November and December, the property was read-only, lending to occassionally annoying use of the control. Master/details displays, typical data-driven forms, and anywhere that you wanted to set this value in code or through a binding would end up running into an exception like this:
This change was checked into our TFS server yesterday, and will be made available on CodePlex and in the toolkit when we next release. For folks who would like to have this fix immediately, I am making available the changes and the updated AutoCompleteBox.cs file (plus associated unit tests).
With the updated file, when the SelectedItem property is set, the Text will be updated as appropriate to match the item. The CLR setter is not public, and the dependency property can also be updated. Let the celebration commence!
Control & test source download
Download the updated source file:
- AutoCompleteBox.cs with the DCR (design change request) implemented
- AutoCompleteBoxTest.cs (updated unit test class)
Updating and building the Microsoft.Windows.Controls.dll file:
- Download the source package for the December toolkit
- Overwrite the AutoCompleteBox.cs with the updated source file
- Rebuild the controls project by opening up the ‘Visual Studio 2008 Command Prompt’ window, navigating to the Source folder of the extracted download, and typing ‘msbuild’
Download the December 2008 release of the Silverlight Toolkit

Important: These downloads do not contain the fix described in this blog post. You’ll need to manually overwrite the AutoCompleteBox.cs file and rebuild per the instructions.
Thanks Jeff!
You ROCK!!!
Thanks Jeff! Much appreciated.
Nice work. Great new feature.
I have run into one behavior that can be problematic.
When binding to a regular TextBox.Text property, the binding doesn’t execute until the TextBox loses focus – indicating that the user has completed their edit.
When binding to the AutoCompleteBox.SelectedItem property, the binding executes as soon as and every time a match is found – before the control loses focus, the signal used by other controls to trigger bindings. In the case of the AutoCompleteBox, a user may hit multiple matches before deciding on their final choice, causing any attached binding logic to execute an unnecessary number of times.
It would be more consistent with the binding behaviors of other similar controls (like DatePicker) to have the binding fire only once the user signals their final choice by moving focus away from the control.
Does this make sense? Is there a place on CodePlex where I should log this as an ‘official’ feature request?
Thanks and keep up the good work!
My mistake: DatePicker binding fires as soon as date is selected, not when focus is lost.