Opening tab with tree node data
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 pageUntil now, I managed to created tree. When tree node is clicked app calls:
UriQuery uriQuery = new UriQuery {{"ID", unit.Id.ToString()}}; 开发者_JAVA技巧
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.
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
精彩评论