自动完成框所选项目不准确

发布于 2024-12-26 15:34:16 字数 431 浏览 0 评论 0原文

我有一个 WPF 应用程序,并且正在 VS 2008 中使用 WPF 工具包自动完成框。我得到的 SelectedItem 属性结果不一致。

我的 ItemSource 数据如下所示(在一个对象中),

Address X - Person A
Address X - Person B

因此它有两个记录,具有相同的地址,但每个记录列出了不同的人。我在自动完成框中的搜索是按地址(也是我的 ValueMemberPath)进行的。因此,当输入地址 X 时,这两个名称都会弹出,没有问题。但是,如果我从下拉列表中选择人员 B(即第二条记录),则 SelectedItem 属性始终是人员 A 的对象。无论我如何选择记录或其他什么,SelectedItem 始终是人员 A,我永远无法让 SelectedItem 返回 Person B。

我做错了什么?

I have a WPF application and am using the WPF toolkit autocomplete box in VS 2008. I am getting inconsistent results for the SelectedItem property.

My ItemSource data is like the following (in an object)

Address X - Person A
Address X - Person B

So its two records, with the same address but each record has a different person listed. My searches in the autocomplete box are by address (which is also my ValueMemberPath). So when Address X is typed in, both of these names pop-up, no problems there. However, if I were to choose Person B from the drop-down list (i.e. the second record) the SelectedItem property is ALWAYS the object for Person A. No matter how I select the records or what not, SelectedItem is always Person A, I can never get SelectedItem to return Person B.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

乱世争霸 2025-01-02 15:34:16

在 AutocompleteBox/ListBox/ComboBox 中按值选择项目时,应确保所选值在项目列表中是唯一的(例如某种 ID),因为当有两个项目时,控件不知道要选择哪个项目具有相同关键属性的项目。因此它将随机发送一个(第一个,因为这实际上不是预期的用例)回视图模型。

当我告诉你有两种可能的物品(“剑道服”、“键盘”)时,你也会遇到同样的问题,其中我拥有以“K”开头的物品,而你必须告诉我我拥有哪一件物品的意思。

我希望我的例子足够容易理解;)

When selecting items by value in an AutocompleteBox/ListBox/ComboBox you should make sure the selected value is unique in the list of items (like an ID of some sort), because the control doesn't know which item to choose when there are two items with the same key property. So it sends a random one (the first, since this isn't actually an expected use case) back to the viewmodel.

It's the same problem you'd have when I told you that there were two possible items ("Kendo Suit", "Keyboard") from which I owned the one that started with a 'K' and you had to tell me which item I meant.

I hope my example is comprehensible enough ;)

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