This project is read-only.

Handling Child/Popup windows

Jun 11, 2010 at 12:25 PM
Edited Jun 11, 2010 at 12:27 PM

Hi everyone, I just wanted to put up for discussion the topic of what would be a best-practice of handling child/popup windows using nRoute. By handling I mean opening them, passing some data to them, getting some result back and perhaps some other scenarios like multiple simultanous popups, modal/modeless stuff etc.

Without nRoute I always had some kind of view service (e.g. IShowDialogService) which I’d call to show a dialog. I implemented this in various projects with various degrees of “generality”: some had .ShowDialog(IDialogViewModel), some had .ShowDialog(object someDataForDialog), some .ShowDialog(Action<Foo> closedCallback) etc. As you can see, the general pattern is that maybe you need to pass some data in and get some data out.

I was thinking how this could be done using nRoute. One option I see (and kind of like) is to just have a generic view service which shows a dialog container of sorts (e.g. a Window) and passes it a URL to navigate to. Then the window would navigate to that URL, which would actually be the content of the popup. My open issues with this approach are:

  • a) how to pass complex data to it (obviously I can’t in the URL; some id could be passed in the URL and then the popup would be responsible for getting the actual data from wherever, but this might be inadequate), and
  • b) how to get a complex result back (e.g. the edited person/address/whatever)

While for b) a message (using channels) would work fine from my point of view, for a) I can’t really say I have a good idea that’s pretty for all cases (e.g. modal/modeless windows, multiple popups at once etc). Again, I'm talking about the case where I'd do this using nRoute to navigate to the actual popup content (which is a point in itself, maybe I shouldn’t really use navigation for this...)

So please share some thoughts on what a good, clean design for this would be.

 Thanks ;)

Jun 11, 2010 at 1:30 PM

Hi, I had put down some thoughts about using dialogs in an earlier post, see http://www.orktane.com/Blog/post/2009/10/23/Web-Xcel-Demo-View-Services-in-nRoute.aspx (note the use of IDisposable). Also, I've got some more ideas about providing a generic hook for dialogs, let me just flesh them out a bit more.

Secondly, you can pass complex data when navigating - this can either be done by setting the parameters property of a "NavigationRequest" or when using the "NavigationAction" behavior you can list named parameters (see http://www.orktane.com/Blog/post/2010/04/28/nRoute-More-Wholesomeness-with-SL-4-and-NET-40.aspx). Note, in terms of a navigation request, Url-parameters are different/seperate from Url-tokens (eg. the CustomerId in "Customers/{CustomerId}/") - but they are merged together as the request is processed. Lastly, I'll just mention that when using channels for communicating with dialogs then probably it is best to use private channels - especially when you could have as you said multiple popups or dialogs.

Rishi

Jun 11, 2010 at 2:17 PM
Well, I'm looking forward to your future blog posts then... ...however I should say that I totally forgot about navigation parameters, I was just "locked" on Url-only parameters, so thanks for that reminder, it kind of solves the problem with passing complex state to the child window...in a nice way :) Adi