Newbie Question

Apr 12, 2010 at 2:20 PM

Salut Laurent,

I use your toolkit with a pleasure (I already made one Prog), now I want to rewrite another (more complex) application, now I have the problem how to Close a (modal) Window (not shuttdown the App)...

I handled a lot of things like Multitheading with no Problem, but I'm not sure how to resolve this little problem. Please give me a little help.

 

Merci

Sascha

Coordinator
Apr 13, 2010 at 8:55 AM

Hi,

Handling dialogs is usually considered a matter of the View. The designer (or the integrator ;)) is the one who decides how the message should be shown, if it is modal or not, etc. There are two ways to handle that which I consider good:

  • Use the Messenger to send a message from the VM to the View. Use a message with a callback (for example NotificationMessageAction<T>). When the view is done showing the message box and the user closed it, execute the callback to notify the VM. Note that there is currently a DialogMessage type in the Messaging namespace that can help you to do that, but you can also build your own message types inspired from this one if you prefer.
  • Use a dialog service. This service is in charge of displaying the messages and calling back the VM. This is slightly more complicated to wire up (because the View needs to know the service), but some people seem to prefer this approach. This has the advantage of using a fully dedicated service for dialog boxes, so the separation of concerns is a bit cleaner. This is the approach that the nRoute framework is taking, as illustrated in this article: http://www.orktane.com/Blog/post/2009/10/23/Web-Xcel-Demo-View-Services-in-nRoute.aspx

Personally I think that view services are elegant, but bring some complexity in the picture that might be too much to handle. Working with messages for this is a bit more straightforward, but both approaches have qualities for sure.

Hopefully this helps,

Laurent

Apr 13, 2010 at 10:17 AM

Hi Laurent,

thanks for your Answer, I already notice this technics for MessageBox, this will be useful for me, but this is not what I want to know in this case. I want to close a normal Window, when the User Click close.

How to handle from a RelayCommand in VM a  this.Close() where this is a Window.

 

a+
Sascha

Coordinator
Apr 13, 2010 at 9:25 PM

Hi,

Here too, I consider that closing a window is in fact the responsibility of the window. Similarly, I built a sample called CleanShutdown where I consider that the responsibility to shut the application down is the responsibility of the Application object. Maybe you can inspire yourself from this sample, it is available at 

http://blog.galasoft.ch/archive/2009/10/18/clean-shutdown-in-silverlight-and-wpf-applications.aspx

Here too, the Messenger is used to dispatch the notification to shut the application down. I would do the same for the window.

HTH,

Laurent

Apr 14, 2010 at 6:37 AM

Bonjour Laurent,

j'ai compris maintenant...

 

Merci Beaucoup

Sascha