I have a ViewModel for a "parent" control which displays two grids. The first grid has parent information and the second grid displays the related children for the selected parent.
This works fine without a hitch. However the issue is that I have to provide an update button. Upon clicking it, the user w开发者_JAVA技巧ill see the children of the selected parent and opt to delete them or not. THis is done via a child window, containing the same grid that displays the related children, however the grid is in "Enabled" mode.
So the question is what pattern to use with MVVM to: 1) get the child window's data? 2) upon successful update within the child window, update the parent?
Thanks,
You should consider utilizing the mediator pattern to enable communication between the view model of your control and the view model of your child window.
See this answer to get a basic overview of the mediator pattern. Using this pattern, one approach you can take is to publish a message when the Update button is clicked that is handled by a listener that shows the child window (the message will carry the child windows data, and be passed to the data context prior to being shown). Upon sucessful update the child window would publish a message that the parent listens for, and this message would carry the information to update the parent.
You might also want to take a look at the User Interaction Patterns section in the PRISM 4 guidance. Even if you are not using PRISM, the general principles and approaches taken are well thought through.
精彩评论