绑定到带有 null 对象和“varies”的集合目的
我有一个组合框,其中 ItemsSource 绑定到对象列表。我需要添加“无”选项和“变化”选项。
将这些选项添加到我的列表中的最佳方式是什么?
I have a combobox with the ItemsSource bound to a list of objects. I need to add a 'None' option and a 'Varies' option.
What is the best way to add those options to my lists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 CompositeCollection 将静态“None”和“Varies”连接到组合框 ItemsSource 中的其他动态项目。以下是 CompositeCollection 的链接:http://msdn。 microsoft.com/en-us/library/system.windows.data.compositecollection.aspx。
如果您在 ItemsSource 中使用字符串或值类型以外的其他内容,则需要创建代表 None 或 Varies 选择的虚拟对象。然后绑定到 SelectedItem 属性并执行所需的附加逻辑来处理其特殊条件。
如果您只是处理值类型或字符串,则可以绑定到 SelectedValue 属性并处理它们的特定条件。
You can use the CompositeCollection to join the static 'None' and 'Varies' to the other dynamic items in your combobox ItemsSource. Here's a link for the CompositeCollection: http://msdn.microsoft.com/en-us/library/system.windows.data.compositecollection.aspx.
If you're using something other than a string or a value type in your ItemsSource you will need to make dummy objects representing the None or Varies selections. Then bind to the SelectedItem property and perform the required additional logic to handle the their special conditions.
If you're just doing value types or strings, you can bind to the SelectedValue property and handle their specific conditions.