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.
I would have a
ShellViewModelcontrolling my overall application. It would contain theTreeNodecollection for the left side, and theOpenTabscollection for the right side. It would also contain theSelectedTabIndexfor the right side, and perhaps theSelectedTreeNodefor the left side if it made sense to do so.When you want to open a new Tab, I would use the
EventAggregatorto publish anOpenTabevent and pass it the selected TreeNode item. TheShellViewModelwould subscribe to those events, and would determine if that object already existed in theOpenTabscollection. If it exists, it simply sets theSelectedTabIndex. If not, it adds the item to theOpenTabscollection before setting theSelectedTabIndexA while back I posted something here on this sort of navigation with MVVM if you’re interested