Region Hoster become region view (child)

Topics: Prism v4 - Silverlight 4
Apr 21, 2011 at 2:19 PM

Hi, I have a very strange behavior.

In my shell, I have 1 region (rootpageregion).

When LoginModule loaded, in it's Initialize() method I call this:




Which register my LoginPage view to rootpageregion and inside this view (LoginPage) there is a region (loginpageregion).

In my LoginPage.OnNavigatedTo I have this:


            IRegion region = _regionManager.Regions[Uri.Login.RegionName];

            if (_loginView == null)
                _loginView = Mef.Container.GetExportedValue<LoginView>();

            if (_roleSelectorView == null)
                _roleSelectorView = Mef.Container.GetExportedValue<RoleSelectorView>();

            if (_testView == null)
                _testView = Mef.Container.GetExportedValue<TestView>();

            switch ((Uri.Login.Parameter)Enum.Parse(typeof(Uri.Login.Parameter), navigationContext.Parameters[Uri.Login.Action], true))
                case Uri.Login.Parameter.LoginView:

                case Uri.Login.Parameter.RoleSelectorView:

                case Uri.Login.Parameter.TestView:

Uri.Login.RegionName is a const: "loginpageregion"

Everything working fine until the code in the _loginView run this code:
            _regionManager.RequestNavigate(Uri.Login.RegionName, Uri.Login.LoginViewUri
                , (e2) =>

e2.Error contains "System.ArgumentException: Value does not fall within the expected range."
The most strange is, before the blue line above executed, "loginpageregion" still has 3 views (see the picture).
After executed, in the red line it has 4 views now. LoginPage view added to it (see the picture).


Am I doing something wrong, please help...

I'm new to prism, thanks.

Apr 23, 2011 at 7:10 AM

It looks like this behavior is related to this thread. Just take a look to my post there.

So everytime I try to navigate back, it will create a new instance.

And since the target is the child region, that's why the new instance is added to it's view.

Spent days to figure this out...