0

I've found this behavior here whilst searching for a way to open/close windows in viewmodels. I implemented the behavior more or less exactly as stated in that answer, except that I changed the inherited Behavior<UserControl>to Behavior<Window>, as I used the behavior in a Window and not a UserControl.

Everything worked well until I tried to change the window.Show() to a dialog window.ShowDialog(). After closing the newly opened window, it would not reopen again.

I figure that has something to do with the way dialogs work?

Is there a way I can change that behavior so it would work with dialogs as well?

(Or did I actually make a mistake implementing it, causing it not to fully function? (In case it works for other people))

Rikidere
  • 39
  • 1
  • 4
  • 1
    I much prefer a `WindowManager` type of service of some sort for handling this. `WindowManager` understands the mapping between views and view-models, and can open and close windows as needed. It is usually exposed through messaging, or as a property on a base view-model class. It makes interacting with the UI much more pleasant. With a proper `interface` it is easy to unit-test as well. – Bradley Uffner Aug 09 '17 at 15:00
  • If you are interested in seeing my own implementation, you can see the source code [here](https://bitbucket.org/BradleyUffner/wpflib/src/c285d0e6e45ef9efe25458c7dbe076f35d8927bd/WpfLib/Services/WindowManager/WindowManagerService.cs?at=master&fileviewer=file-view-defaultc). All other MVVM libraries that I've looked at have some sort of mechanism for handling this. – Bradley Uffner Aug 09 '17 at 15:07

0 Answers0