绑定到带有 null 对象和“varies”的集合目的

发布于 2024-12-19 16:07:12 字数 87 浏览 3 评论 0原文

我有一个组合框,其中 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡看悲欢离合 2024-12-26 16:07:12

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文