View navigation in a child window

Mar 11, 2011 at 12:31 AM

This is a theoretical question that I hope will save me some time down the road.  I have a BXF based SL application that launches a modal (child) window.  I need to be able to navigate between various views within the child window after it has loaded based on button trigger click events, all from within the child.  I have a home state view in the child window that will have any number of buttons.  Each button, when clicked, needs to load one view that could potentially have another button that would load another view or a button that would load the home state view again.  All of the navigation happens in the child window and it does not interact with the parent, except to be closed.

I'm thinking to accomplish this I need to call .ShowView(view, viewcontext, vm object, region) from the child window on a triggeraction to fire the OnShowView presenter event handler?  My presenter is defined in my hosting XAML page (MainPage.xaml) which creates the child.  Will the OnShowView presenter still respond from the parent window to a call to ShowView from the child window?  I believe it should but confirmation would be helpful.

Also, since the child window is not under page navigation control, would the best approach to take to change the child view be to get a handle to the child window and then set the child LayoutRoot to the passed in view?  Or is there another approach that would work better?

Thanks.

Coordinator
Mar 11, 2011 at 12:55 AM

The ideal solution is probably for Bxf to allow instancing of the shell, so you could have an independent shell (with its own IPresenter handlers) for a sub-region of the UI - such as within your modal dialog.

The current version of Bxf uses a singleton pattern for the shell, so there can be only one for the whole app.

What this means is that your IPresenter handler (the OnShowView handler specifically) needs to be smart enough to handle your scenario by routing requests to the main viewmodel for the child window. This main child window viewmodel will be a "mini-presenter" of sorts - much like the main presenter is for the main shell window, but only for the child window.

You probably have a region named "ModalDialog" (or something) already. And that's used by the rest of the app to display initial content in the modal window.

The easiest thing to do is to use a prefixing scheme like "ModalDialog.blah" where blah is the name of the child window's sub-region where the content should appear.

Your main window IPresenter handler class will need to maintain a reference to the viewmodel for the child window, after it displays the initial child window content.

As requests come in to show a view in "ModalDialog.blah", those requests should be relayed to a method on the child window's main viewmodel, and the child window viewmodel can take appropriate steps to display the view - probably by setting a DependencyProperty to the view.Instance for the blah sub-region.

I don't have time to put together a sample, so hopefully this makes some sense.

 

Mar 11, 2011 at 2:25 PM

Thanks Rocky.  Yes, that makes sense and confirms the direction I was going with it.  No need for a sample.  I appreciate your quick and detailed response.