Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ComboBox with empty item?

Tags:

combobox

wpf

Suppose we have a DataSource bind to a collection from Database. There is no null item of course. How to add a void item into a ComboBox, so that at first load user would see an empty string. I don't want to add a dummy/void object into the Collection. Optimally in XAML. Any proposals?

like image 387
theSpyCry Avatar asked Jul 27 '09 14:07

theSpyCry


1 Answers

<ComboBox Name="myComboBox" Width="200" Background="White">         <ComboBox.ItemsSource>             <CompositeCollection>            <ComboBoxItem IsEnabled="False" Foreground="Black">Select Item</ComboBoxItem>            <CollectionContainer Collection="{Binding Source={StaticResource DataKey}}" />             </CompositeCollection>     </ComboBox.ItemsSource> </ComboBox> 

EDIT

As @surfen mentioned in comment, BindingProxy is workaround for the binding issue

like image 138
Arsen Mkrtchyan Avatar answered Sep 21 '22 23:09

Arsen Mkrtchyan