There is an interesting post discussing communication patterns between view models.
I recently struggled to implement a modal dialog in a WPF MVVM application, but there more I think about it the more I see reasons for why it's difficult and why there's no built-in helpers to achieve this. Targeting different platforms only strengthen this view: what may look suitable for a modal dialog showing selected item details is usually implemented by navigating to a different view on mobile devices.
So my questions to those who successfully implemented MVVM pattern and avoided code-behind: did you also avoid modal dialogs? What replacements have you found suitable? I can think of at least two:
- Place child (modal) view in a new view and implement communication between parent and sub-model using pub/sub;
- Add a panel with a child control directly to a parent view and just turn its visibility to activate child view as a popup simulating modality.
The second approach is surely more limited, it does not really work when the parent view can spawn various child views, but it looks suitable when the parent view needs to display a small single popup. Or is it better to go for the first approach as the more generic. Are there other alternatives?