I use one region with 2 views. I have a ComboBox
that let the user to select view in region.
I have 2 questions:
First question is what is the difference between:
_regionManager.Regions.Add("MyRegion")
_regionManager.Regions["MyRegion"].Add(container.Resolve<OneView>())
_regionManager.Regions["MyRegion"].Add(container.Resolve<SecondView>())
To:
_regionManager.RegisterViewWithRegion("MyRegion", () => container.Resolve<OneView>());
_regionManager.RegisterViewWithRegion("MyRegion", () => container.Resolve<SecondView>());
and my second question is what is the difference between:
_regionManager.Regions["MyRegion"].ActiveViews.ForEach(view => _region.Deactivate(view));
_regionManager.Regions["MyRegion"].Activate(container.Resolve<SecondView>());
To:
_regionManager.Regions["MyRegion"].RequestNavigate(new Uri("SecondView", UriKind.Relative));
Thanks in advance.
The difference on the first comparison you mentioned would be that RegisterViewWithRegion() method activates the registered View at the end of the process while the first implementation only adds the Views. This RegisterViewWithRegion() approach is called View Discovery. You may find a related answer in the following post made by you yesterday:
Helpful information on MSDN Prism Guide:
For the second comparison, it would depend on the Region type. The First implementation would only leave the SecondView activated. However, RequestNavigate() may not deactivate the previous View if the Region is an ItemsControl type. An ItemsControl Region lets you append many Views so you can have more than one active View.
If this is the case, the SecondView would appear below the previously active View in the Region. But if you don't want this behavior you have 2 options:
Helpful information about RequestNavigate() and Navigation on MSDN Prism Guide:
I hope this helps, Regards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With