打开包含树节点数据的选项卡
你好,
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将有一个 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 theTreeNode
collection for the left side, and theOpenTabs
collection for the right side. It would also contain theSelectedTabIndex
for the right side, and perhaps theSelectedTreeNode
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 anOpenTab
event and pass it the selected TreeNode item. TheShellViewModel
would subscribe to those events, and would determine if that object already existed in theOpenTabs
collection. If it exists, it simply sets theSelectedTabIndex
. If not, it adds the item to theOpenTabs
collection before setting theSelectedTabIndex
A while back I posted something here on this sort of navigation with MVVM if you're interested