Click here to Skip to main content
13,900,817 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 30 Apr 2014
Licenced Apache

WPF: Editable ComboBox Text Disappears

, 30 Apr 2014
Rate this:
Please Sign up or sign in to vote.
WPF: Editable ComboBox Text disappears


ComboBox looks like a simple thing, but it’s surprisingly hard to get right. Today, I bumped into another bug (or feature) of the WPF combo-box. I am recording it here, so I don’t forget the details.

Suppose you have a ComboBox. The user selects an item in the combobox. ComboBox’s ItemSource then changes. If previously selected item is still in the items list, nothing happens. However, if previously selected item is not in the list, the Text property will become an empty string. This kind of makes sense for drop-down lists, but for editable combo-boxes, it looks odd.


You use a combobox to display a list of countries. You have three country lists: for Europe, Asia, Africa, and null list. Let’s say you start with Europe and the user selects Russia. Then, you switch the list to Asian countries. Russia is there too, so everything’s fine. Then you switch to African countries, and voila: user selection disappears.

An unexpected feature is that if the combo-box is editable and the user types R-u-s-s-i-a instead of selecting an item from the drop-down, the text will not disappear and will remain even if you switch to an items list not containing Russia.

I wrote a little attached behavior that prevents the combo-box from losing the text when previously selected item is no longer in the list. You use it like this:

<ComboBox IsEditable="True" Text="{Binding Something}" 


The extension source code can be found here: ComboBoxUtils.cs

A complete sample program demonstrating how it works can be found here:

Main view: MainWindow.xaml

The view model: MainViewModel.cs


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site:

You may also be interested in...

Comments and Discussions

QuestionMessage Closed Pin
27-Oct-15 16:35
memberMember 1200320627-Oct-15 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 30 Apr 2014
Article Copyright 2014 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid