ComboBox with empty item?

PaN1C_Showt1Me picture PaN1C_Showt1Me · Jul 27, 2009 · Viewed 52.9k times · Source

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?

Answer

Arsen Mkrtchyan picture Arsen Mkrtchyan · Jul 27, 2009
<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