组合框与空项目? [英] ComboBox with empty item?

查看:102
本文介绍了组合框与空项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个DataSource绑定到数据库的集合。当然没有null项目。如何向组合框中添加无效项,以便首次加载用户将看到一个空字符串。我不想在集合中添加一个dummy / void对象。 在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>

EDIT

由于评论中提及了 @surfen BindingProxy 是绑定问题的解决方法

As @surfen mentioned in comment, BindingProxy is workaround for the binding issue

这篇关于组合框与空项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆