Handle ChildWindow closing event

Topics: Prism v2 - Silverlight 2, Prism v2 - Silverlight 3
Sep 10, 2009 at 2:15 PM


I have a User Control that, on a button click, open, through a delegate command attached to the button click, a ChildWindow, that is managed by its view model.

When the user click on the Ok or Cancel button in the ChildWindow, I want close the ChildWindow.

I know that this is simple using childWindow.DialogResult = true in the codeBehind; but I'm using ViewModels and I'd like to do this through its view model.

How could I perform this?

Thank you

Sep 11, 2009 at 10:48 PM


If you are set with having no code behind in the view, once possible way to achieve this could be passing the ChildWindow as a Command Parameter, and setting the DialogResult property in the command. You can read more about that in this thread.

However, in my personal opinion, it might not be necessary to avoid having code behind in a ChildWindow. Perhaps having a method in its interface which is in charge of setting the DialogResult based on a model parameter, and handling it in the code behind could be a better approach (of course the model would be keeping a reference to the view). You can read more about some criterion for adding/not adding code-behind to views when using MVVM in this post by Glenn Block:

Please let me know if this helps.

Damian Schenkelman