May 18, 2010 at 9:57 AM
Edited May 18, 2010 at 10:00 AM
I have been franticly digging through PRISM guides for the past 2 months in anticipation of a new project we have to get into. So far I am very impressed and confused at the same time. It will be my first really big system rewrite from scratch, so naturally
I want to do everything top notch and proper. I have roughly 2million questions about PRISM but I won't burden you with all of them at once.
My question for now is this:
I have created a shell with 5 regions. I have created a login module which gets loaded .WhenAvailable. On startup the shell does what it needs to and the login module is displayed as I desire. After successful login, I get into my (still empty for now) shell.
Then I click the Logout button I have added into one of the regions. This basically runs through all the regions and removes all the views and sets up the shell to be as it is when it first started up ie. Login Layout.
Now my problem comes in here where I want to show my login screen again. The login module has already been loaded and registered with the region in the bootstrapper and the module's initialize() method. On startup the Bootstrapper kicks off the login module
and loads it up automatically. But once I remove the login view from my shell, how do I get it to come back. The login button is in another module called ActiveUserModule (but still in the same project) as the login module. I thought I should do something
like this, but the new LoginViewModuleViewModel(...) part seems to tell me that I should not. Here is my LogoutCommand's Execute function.
public void ExecuteLogoutCommand(object parameter)
foreach (IRegion region in regionManager.Regions)
if (region.Name == RegionNames.ContentRegion)
// remove the views from the regions
while (region.Views.FirstOrDefault() != null)
var view = region.Views.FirstOrDefault();
if (view != null)
IRegion contentRegion = regionManager.Regions[RegionNames.ContentRegion];
object existingView = contentRegion.Views.FirstOrDefault();
if (existingView == null)
LoginView view = new LoginView([ ILoginModuleViewModel implementation should go here]);
Here is my View's constructor
public LoginView(ILoginModuleViewModel viewModel)
this.DataContext = viewModel;
Here is the ViewModuleViewModel implementation
public LoginModuleViewModel(ILoginService loginService, IRegionManager regionManager, IEventAggregator eventAggregator)
this.loginService = loginService;
this.regionManager = regionManager;
this.eventAggregator = eventAggregator;
When I say
I need to pass all of the paramaters which usually get dependancy injected.
LoginView view = new LoginView(new LoginModuleViewModel(blahblah);
Am I missing something? Am I completely wrong? How do I load back my Login module after logout? Any ideas would be greatly appreciated, and thanks for an awesome framework :)