I am developing a composite WPF application using PRISM. I have a window which has a parent UserControl. This parent usercontrol has many child Regions defined. child views exports themselves using MEF's "REGIONEXPORT" attribute. Each child view imports/creates its own viewmodel. The parent usercontrol has "OK" and "Cancel" button. On pressing "OK" i want to validate and save all childviewmodels. If any validation fails then the parent usercontrol's viewmodel needs to know. To achieve this I am using a composite command and setting it in RegionContext. Each child viewmodel gets that composite command through region context and Hope you understand that basically i need to share data between parent and child viewmodels. So I need to get the RegionContext in the child viewmodel for that I am importing the RegionManager in the viewmodel's constructor (using importing construtor,) from RegionManager i get the region context and then the commands.
public class FooViewModel
{
[ImportingConstructor]
public FooViewModel(IRegionManager regionManager)
{
var regionContext = regionManager.RegionContext;
}
}
- Is it a good practive to have region manager in viewmodel??
- Doesn't this break MVVM? we have view related stuff's in viewmodels
- Is there any better approach to share data between viewmodels (other than event aggregators)