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
2009-07-27 14:22:52
OK wonderful. But how to make the first item nonselectable? Only datasource items can be selected.
PaN1C_Showt1Me
2009-07-27 14:31:15
See edited post, you just need to add IsEnabled="False" Foreground="Black" to items properties
ArsenMkrt
2009-07-27 14:43:51
OK sorry I didn't notice that properties. Thank you !
PaN1C_Showt1Me
2009-07-27 14:47:33
I can't seem to get this to work in a ViewModel binding scenario... Any ideas?
Anderson Imes
2009-07-27 15:41:36
Ah... I figured it out. CompositeCollection is not Freezable, so it won't work with binding. Unfortunate.
Anderson Imes
2009-07-27 15:52:32
A:
I do something similar with a converter, however i allow selection of the null here
Aran Mulholland
2009-07-28 07:23:36