带有空项目的组合框? [英] ComboBox with empty item?
本文介绍了带有空项目的组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有一个 DataSource 绑定到一个来自 Database 的集合.当然没有空项目.如何将 void 项添加到 ComboBox,以便在第一次加载时用户会看到一个空字符串.我不想在集合中添加一个虚拟/空对象.最好在 XAML 中.有什么建议吗?
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?
推荐答案
<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>
编辑
正如评论中提到的 @surfen,BindingProxy 是绑定问题的解决方法
As @surfen mentioned in comment, BindingProxy is workaround for the binding issue
这篇关于带有空项目的组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文