打开包含树节点数据的选项卡

发布于 2024-12-04 22:16:11 字数 932 浏览 1 评论 0原文

你好,
我是 Prism 和 WPF 的新手,我有一个关于在视图之间共享数据的问题。 我正在开发的应用程序类似于 SQL Server Development Studio。演示包含两个区域。第一个区域包含树(如 SQL Server DS 中的对象资源管理器)。树节点绑定到不同的视图模型。示例是DatabaseA->Tables->dbo.TableA->Columns 等。

第二个区域最初是空的。当我双击树节点时,我想打开显示我在树中单击的数据的视图。
详细:
1.双击树节点
2.节点数据并显示在第二个区域
3.如果第二个区域不为空,检查点击的节点数据是否已经显示在现有选项卡页面之一
4.如果没有,则使用单击的节点数据创建新选项卡页,否则聚焦现有选项卡页

到目前为止,我成功创建了树。单击树节点时,应用程序调用:

UriQuery uriQuery = new UriQuery {{"ID", unit.Id.ToString()}};  
uriQuery.Add("TypeName", "Unit");  
var uri = new Uri("DebugTreeItemView" + uriQuery, UriKind.Relative);  
RegionManager.RequestNavigate("SECOND_REGION", uri);  

这将使用选项卡控件打开视图,我可以获取 uri 参数。但我对这个解决方案并不满意。我需要一种方法:
1. 拦截此 RegionManager.RequestNavigate 调用以检查选项卡控件是否已创建。另外,我需要检查单击的节点数据是否尚未显示在现有选项卡页面之一中。
2. 我想将 Unit 对象直接发送到选项卡控件视图,而不是发送 ID 和类型名。实现这一目标的最佳方法是什么?

谢谢。

Hi,
I'm new to both Prism and WPF, and I have a question regarding sharing data between views.
Application I'm working on resembles SQL Server Development Studio. Demo contains two regions. First region contains tree (like Object explorer in SQL Server DS). Tree nodes are bound to different view models. Example would be DatabaseA->Tables->dbo.TableA->Columns etc.

Second region is initially empty. When I double click on tree node I would like to open view that displays data I clicked in tree.
In detail:
1. double click on tree node
2. node data and display it in second region
3. if second region isn't empty, check if clicked node data is already displayed in one of existing tab pages
4. if not, create new tab page with clicked node data, otherwise focus existing tab page

Until now, I managed to created tree. When tree node is clicked app calls:

UriQuery uriQuery = new UriQuery {{"ID", unit.Id.ToString()}};  
uriQuery.Add("TypeName", "Unit");  
var uri = new Uri("DebugTreeItemView" + uriQuery, UriKind.Relative);  
RegionManager.RequestNavigate("SECOND_REGION", uri);  

This will open view with tab control and I can fetch uri parameters. But I'm not satisfied with this solution. I need a way to:
1. intercept this RegionManager.RequestNavigate call in order to check if tab control is alread created. Also, I need to check that clicked node data isn't already displayed in one of existing tab pages.
2. I would like to send Unit object directly to tab control view instead of sending ID and typename. What is the best way to achieve this?

Thanks.

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

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

发布评论

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

评论(1

季末如歌 2024-12-11 22:16:11

我将有一个 ShellViewModel 来控制我的整个应用程序。它将包含左侧的 TreeNode 集合和右侧的 OpenTabs 集合。它还将包含右侧的 SelectedTabIndex 以及左侧的 SelectedTreeNode(如果这样做有意义的话)。

当您想打开一个新选项卡时,我将使用 EventAggregator 发布 OpenTab 事件并向其传递选定的 TreeNode 项。 ShellViewModel 将订阅这些事件,并确定该对象是否已存在于 OpenTabs 集合中。如果存在,它只是设置SelectedTabIndex。如果没有,它会在设置 SelectedTabIndex 之前将该项目添加到 OpenTabs 集合中

不久前我发布了一些内容 这里 如果您有兴趣,可以了解 MVVM 的此类导航

I would have a ShellViewModel controlling my overall application. It would contain the TreeNode collection for the left side, and the OpenTabs collection for the right side. It would also contain the SelectedTabIndex for the right side, and perhaps the SelectedTreeNode for the left side if it made sense to do so.

When you want to open a new Tab, I would use the EventAggregator to publish an OpenTab event and pass it the selected TreeNode item. The ShellViewModel would subscribe to those events, and would determine if that object already existed in the OpenTabs collection. If it exists, it simply sets the SelectedTabIndex. If not, it adds the item to the OpenTabs collection before setting the SelectedTabIndex

A while back I posted something here on this sort of navigation with MVVM if you're interested

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