I am working on my first project in MVVM and I\'ve chosen to use the MVVM Light Toolkit. I have a GameViewModel
that handles business on the main screen of my g
Ok I put together a demo that should make this hopefully easier for you Download Link
Functionality:
MainWindow
, ModalWindow
, NonModalWindow
)MainWindow
has a TextBox
you can type whatever you want into.TextBox
in a TextBlock
inside them.CheckBox
to update the value in result's textblock in MainWindow
(For the Modal Window this will kick in when modal window is closed. For NonModal changes can be seen asap)That's it for functionality,
Concepts:
SimpleIoC
and using GetInstance(...)
to request them out.OpenWindowMessage
Important Note:
- The method used in this example to set the non DP DialogResult
from the modal window is not MVVM friendly cos it uses code-behind to set the DialogResult
property on a Window.Closing
event which should be avoided(If needing to be "testable"). My preferred approach is a bit long and is very well documented HERE(Mixture of question and answer). Hence why I ignored it for the sake of this sample.
Follow up to Viv, I modified the sample to include an example of opening the window without using a code behind.
Sample project is here.
I'm utilizing the ViewModelLocator singleton with a static method that news up the viewmodel and window and Data Context instead of the code behind.
Blog Post with Details. Let me know which method is preferable. I dislike using code behind, but there could be pro's and con's I'm missing.