The Prism region adapter I wrote for the xamDockManager has become much more popular than I would have ever thought. My last update to the xamDockManger Prism region adapter was back in March. That update included some refactoring and support for programmatic view activation and removal , and support for floating panes. Originally the xamDockManager Prism region adapter was designed with View first MVVM development in mind. Meaning that you would actually inject Views, in the form of a UI control, into the xamDockManager regions. Well, I have gotten a number of requests to support ViewModel first MVVM development, in which you inject ViewModels into the xamDockManager region and you control the creation of the Views with DataTemplates. I also had some bugs reported when dealing with nested regions within the xamDockManager. So lets take a look at the updated xamDockManager Prism region adapter.
The structure remains unchanged:
The Updated Region Adapter in Action
Nothing here has really changed from the previous posts. The main difference is now you can inject ViewModels and use DataTemplates to control your Views. Let’s take a look at the ShellViewModel.
As you can see, we are no longer referencing any type of View in the ViewModel. You are only acting against the ViewModels. This is a good thing, and I always suggest removing any type of View related objects out of your ViewModel. To render our View, we just create a DataTemplate that defines how the View should look for each instance of the inject ViewModel.
This DataTemplate is being applied implicitly to all instances of type ViewAViewModel. There is not a single View defined in the module. Now you can deliver a much more MVVM friendly application using the xamDockManager in using Prism.
Feel free to download the new and improved XamDockManager Prism region adapter with sample source code. I probably haven’t covered every possible use of this adapter, so if you find a scenario that should be support let me know. If you have any questions feel free to contact me through my blog, on twitter (@BrianLagunas), or leave a comment below.