WPF TreeView 取消 TreeViewItem 选择

发布于 2024-11-07 07:54:48 字数 338 浏览 2 评论 0原文

我一直在寻找这个问题的解决方案,但我仍然找不到合适的解决方案。请帮忙。基本上,我有一个绑定到对象列表的树视图。当用户单击树视图项时,我会根据树视图项加载数据网格的数据。用户可以更改网格中的数据。如果数据网格发生更改并且用户单击另一个树视图项,系统会要求用户保存。用户可以选择是、否或取消。当用户选择取消时,应用程序必须使用户停留在当前树视图项上,直到他/她保存数据网格。问题是一旦用户选择了另一个树视图项目,我就无法再次选择之前的选择。没有“SelectedItemChanging”事件。 WPF 树视图仅具有 SelectedItemChanged 事件。我尝试了多种解决方案,但最终总是得到无限的解决方案。请提供任何提示或建议。

谢谢, 明

I've been looking for a solution to this problem but I still can't find an adequate solution yet. Please help. Basically, I have a treeview that's bound to a list of objects. When the user clicks on a treeviewitem, I load data for a data grid based on the treeviewitem. The user can change data in the grid. If there's a change in the data grid and the user clicks on another treeviewitem, the user is asked to save. The user can choose Yes, No, or Cancel. When the user chooses cancel, the application has to make the user stay on the current treeviewitem until he/she saves the data grid. The problem is once the user has selected another treeviewitem, I can't make it so that the previous selection is selected again. There is no "SelectedItemChanging" event. WPF treeview only has SelectedItemChanged event. I'm trying multiple solutions but I always end up with an infinitely. Please offer any tips or advices.

Thanks,
Minh

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

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

发布评论

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

评论(1

亢潮 2024-11-14 07:54:48

您可以只使用一个私有字段来存储最后选择的项目,只需处理 SelectedItemChanged 事件并始终根据需要更新该字段。另外,正如 Dave Clemmer 建议的那样,拥有一个可以绑定的 IsSelected 属性有助于以编程方式选择项目。

You could just use a private field in which you store the item which was selected last, just handle the SelectedItemChanged event and always update the field as required. Also as Dave Clemmer suggested having an IsSelected property to which you can bind helps with selecting items programatically.

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