views:

2248

answers:

2

Hi! 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?

+2  A: 
<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>
ArsenMkrt
OK wonderful. But how to make the first item nonselectable? Only datasource items can be selected.
PaN1C_Showt1Me
See edited post, you just need to add IsEnabled="False" Foreground="Black" to items properties
ArsenMkrt
OK sorry I didn't notice that properties. Thank you !
PaN1C_Showt1Me
I can't seem to get this to work in a ViewModel binding scenario... Any ideas?
Anderson Imes
Ah... I figured it out. CompositeCollection is not Freezable, so it won't work with binding. Unfortunate.
Anderson Imes
A: 

I do something similar with a converter, however i allow selection of the null here

Aran Mulholland