可编辑的组合框绑定列表中重视不 [英] Editable ComboBox with binding to value not in list

查看:204
本文介绍了可编辑的组合框绑定列表中重视不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可编辑的组合框,其中pferred并不总是$ P $产品在下拉列表中。

I have editable combobox where not always the preferred item is in the drop-down list.

我想在文本框中被传播到绑定到的SelectedValue字符串手动输入文本的可能性。

I would like to have the possibility of manually entering text in the textbox which is propagated to the string bound to SelectedValue.

现在绑定到的SelectedValue该字符串仅在输入的值是对那些在ComboBox项目更新。

Right now the string bound to SelectedValue is only updated if the entered value is on of the ones in the ComboBox items.

如何允许在组合框列表中不可用的自定义值手动输入并正确传播到限值?

How do I allow custom values not available in the ComboBox list to be manually entered and properly propagated to bound value?

推荐答案

我只是在做这个昨天+今天,它​​看起来像如下:

i was just doing this yesterday+today and it looks like the following:

1)设置组合框 IsEditable =真正的

2),而不是绑定绑定到的SelectedItem ,到文本组合框的属性

2) instead of binding to SelectedItem, bind to the Text property of the combobox

3)如果你绑定到一个自定义的对象,而不是只是字符串,你也需要设置 TextSearch.TextPath =NameOfField。这让文本搜索行为的工作,也说明了这个属性在文本框中为好。

3) if you're binding to a custom object instead of just strings, you need to also set TextSearch.TextPath="NameOfField". This lets the text search behavior work, and also shows this property in the textbox as well.

所有的一切,我结束了是这样的:

All in all, I ended up with something like:

        <ComboBox x:Name="c" IsEditable="True" IsTextSearchEnabled="True" 
              IsTextSearchCaseSensitive="False" StaysOpenOnEdit="True"
              Text="{Binding NameOnViewModel}"
              TextSearch.TextPath="NameOnChildItems"  
              ItemsSource="{Binding Items}" 
              ItemTemplate="{StaticResource DataTemplate}" />

        <TextBlock Text="{Binding ElementName=c,Path=Text}"/>

这篇关于可编辑的组合框绑定列表中重视不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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