使用ItemsSource将预定义项添加到ComboBox [英] Adding predefined item to a ComboBox with ItemsSource
问题描述
我试图添加一个预定义的ComboBoxItem到我已经有一个ItemsSource属性设置的ComboBox。示例:
I'm trying to add a predefined ComboBoxItem into my ComboBox which already has a ItemsSource property set. example:
(Select item)
Item 1
Item 2
Item 3
可以在不修改原始项目集合的情况下这样做?
It's possible to do this without modifying the original items collection?
推荐答案
下面是来自MSDN的一些示例代码,显示了CompositeCollection的用法:
Here is some sample code from MSDN that shows the usage of CompositeCollection:
<ComboBox>
<ComboBox.ItemsSource>
<CompositeCollection>
<ListBoxItem>Please Select</ListBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource YOURDATASOURCE}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
以下是一些参考资料,显示了CompositeCollection的用法:
Here are some references to show you the usage of CompositeCollection:
1- http:// msdn .microsoft.com / en-us / library / system.windows.data.compositecollection.aspx
2- http://robertbouillon.com/2010/04/17/adding-items -to-a-data-bound-wpf-combobox /
3- 如何转换ComboBox以使用绑定的CompositeCollection?
这篇关于使用ItemsSource将预定义项添加到ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!