After weeks of using Prism I have been through every kind of navigation methods. But there is still one thing that I haven’t been able to achieve with Prism “out-of-the-box”: navigate to a view-model instance. It is really easy to navigate to a view-model or view type but there is actually no way to navigate to a real view-model instance.
For example when I have a list of different view-model instances (different type too), if one is selected and I want to display it in my content region, I cannot achieve it unless I publish the change through event aggregation and I do not want that because this gets me stuck to one kind of view in my content region. What I want to do is to register a view-model instance into a region, so the view can load dynamically from data templates.
Actually I achieved to do this by creating a RegisterViewModelWithRegion as an extension method to RegionManager, it works well but it is not really neat as I have to manually lookup through my application resources, load the view, attach my view-model instance and then add the view to my region.
I really feel that I am missing something into the architecture because this kind of practice seem obvious to me but apparently I cannot find anybody having the same concern.
Your help and experience would much appreciated.
Thanks.
After some discussions with the Prism team, I found out that actually, using the
Region.Add(object view)method to inject a view-model in a region is totally ok. It will give exactly the same result (except for some minor case).I inspected the ItemsControlRegionAdapter and all it does in the end is
regionTargetbeing the target control (ListBox for example) andregion.Viewsproperty being the objects you inject into your regions.Of course, thanks for your help Rachel 🙂