Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between region activation and region RequestNavigate?

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.

like image 854
user436862 Avatar asked Feb 18 '14 10:02

user436862


1 Answers

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:

  • What is the difference between register a region to adding a region in prism?

Helpful information on MSDN Prism Guide:

  • Composing the User Interface

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:

  1. Make the Region type as a ContentControl, so only one View would be displayed at a time;
  2. Deactivate the previous View inside the OnNavigatedFrom() method. You would need to make the previous View inherits from INavigationAware.

Helpful information about RequestNavigate() and Navigation on MSDN Prism Guide:

  • View-Based Navigation

I hope this helps, Regards.

like image 145
GOstrowsky Avatar answered Oct 20 '22 15:10

GOstrowsky