Append Items to Databound ItemsControl in WPF?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

The simplest way I've found to do this is to insert a "special" value into the underlying collection, and display the "(None)" text when it's selected. Obviously then you need to run your binding through a converter to take this value into account and return null when it's selected. (See this question of mine which was a result of me trying to add an actual null value to a ComboBox's underlying collection.

).

Up vote 2 down vote favorite share g+ share fb share tw.

I've got a Combo Box that is databound to an ObservableCollection of items. I would like to have a default selected item that is (None) that would set the value of the property I've bound to "SelectedValue" to null. I think there ought to be a way to achieve this with some combination of Style/DataTemplate/TemplateSelector.

I'm trying to design this with MVVM in mind, so I'd like something that doesn't use codebehind and is as reusable as possible. I'd also like the benefits of the ObservableCollection (updating the collection causing the control to rebind) to remain intact. Bonus part B: I would like to also be able to append an extra visual element to the bottom of an ItemsControl as well.

I was thinking it would be easy to change the DataTemplate if I knew how to trigger it on the last item of a collection. Willing to entertain other options here. Wpf data-binding itemscontrol link|improve this question edited Aug 5 '11 at 19:28Dave Clemmer1,78331030 asked Jul 16 '09 at 6:05Anderson Imes12.1k12050 100% accept rate.

The simplest way I've found to do this is to insert a "special" value into the underlying collection, and display the "(None)" text when it's selected. Obviously then you need to run your binding through a converter to take this value into account and return null when it's selected. (See this question of mine which was a result of me trying to add an actual null value to a ComboBox's underlying collection.

) Having said that, it might actually be possible to do what you want with the CompositeCollection class. You could make a separate collection (with only one item - your Null item) and bind your ComboBox to both it and your original collection through the CompositeCollection.

I've tried this. I'm not getting much luck binding a CollectionContainer's "Collection" property to a property from the object in DataContext (ex. ).

Works great from a static resource though... am I missing something here? – Anderson Imes Jul 16 '09 at 6:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions