Domanda

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.

È stato utile?

Soluzione

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:

  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:

I hope this helps, Regards.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top