可编辑的组合框,绑定到不在列表中的值
我有可编辑的组合框,其中首选项目并不总是位于下拉列表中。
我希望能够在文本框中手动输入文本,该文本将传播到绑定到 SelectedValue 的字符串。
现在,仅当输入的值位于 ComboBox 项中的值中时,绑定到 SelectedValue 的字符串才会更新。
如何允许手动输入 ComboBox 列表中不可用的自定义值并将其正确传播到绑定值?
I have editable combobox where not always the preferred item is in the drop-down list.
I would like to have the possibility of manually entering text in the textbox which is propagated to the string bound to SelectedValue.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我昨天和今天刚刚这样做,它看起来如下:
设置组合框
IsEditable="true"
不是绑定到
SelectedItem
,而是绑定到组合框的Text
属性,
如果您要绑定到自定义对象而不仅仅是字符串,则还需要设置
TextSearch.TextPath="NameOfField"
。这可以让文本搜索行为正常工作,并且还在文本框中显示此属性。总而言之,我最终得到了类似的结果:
I was just doing this yesterday and today and it looks like the following:
set the combobox
IsEditable="true"
instead of binding to
SelectedItem
, bind to theText
property of the comboboxif 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:
将绑定设置为 Combo 的 Text 属性也足够了。
Setting the binding to Text property of Combo will suffice as well.