以编程方式搜索和选择 TreeView 项目?

发布于 2024-07-19 08:14:55 字数 217 浏览 3 评论 0原文

在我的 3d 应用程序中,我有一个 TreeView,它与 3d 场景中的对象的 ObservableCollection 进行数据绑定。 理论上,用户可以单击 3D 视图中的对象,这应该更新 TreeView 以选择相应的项目。 但我不知道具体怎么做。 我所拥有的只是用户选择的 3D 对象。

我该怎么做呢?

In my 3d application, I have a TreeView that is databound to an ObservableCollection of objects in my 3d scene. In theory a user can click on an object in the 3d view, which should update the TreeView to select the corresponding item. But I don't exactly know how. All I have is the 3d object the user picked.

How do I go about doing this?

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

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

发布评论

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

评论(2

野の 2024-07-26 08:14:55

Found the solution right here.

http://blog.quantumbitdesigns.com/2008/07/22/programmatically-selecting-an-item-in-a-treeview/

And he's got sample source code that works, which kicks all kinds of ass.

雨巷深深 2024-07-26 08:14:55

我假设树视图和场景项将共享(并由其标识)一个公共 ID 值。 然后,在您的 3D 场景或 Treeview 中,实现并订阅 OnSelectionChanged,您的 TreeView 可能已经有了。 然后,当其中一个更新/更改时,应立即通知另一个,并相应地更新自身。 当然,即使在更新时也要确保吃掉更改,否则您将创建令人讨厌的 OnChange 事件循环。

...或者,我误解了你的问题吗?

I would assume both the treeview and scene item would share ( and be identified by ) a common ID value. Then, in either your 3D scene or Treeview, implement and subscribe to an OnSelectionChanged, which your TreeView probably already has. Then, when one is updated/changed, the other should be notified instantly, and update itself accordingly. Be sure of course to eat the change even on the update or you will create a nasty loop of OnChange events.

... or, did I misunderstand your question?

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