Add a workspace after system load in WPF with Cinch

Jul 5, 2012 at 3:47 PM

Hiya,
 
I am using the Cinch framework in order to build my application and at present have the following code which is run in the MainWindowViewModel to add items to the Workspace in the Main Window:
 

  
 WorkspaceData loginWorkSpace = new WorkspaceData(null, "LoginUserControl", null, "Login", true);
            WorkspaceData aboutWorkspace = new WorkspaceData(null, "About", null, "About", true);
            WorkspaceData viewAlbumsWorkspace = new WorkspaceData(null, "ViewAlbums", null, "View Albums", true);
            WorkspaceData readReviewSelectWorkspace = new WorkspaceData(null, "ReadReviewsSelect", null, "Select Review", true);
            WorkspaceData adminWorkspace = new WorkspaceData(null, "Admin", null, "Admin", true);
 
            Views.Add(aboutWorkspace);
            Views.Add(loginWorkSpace);
            Views.Add(readReviewSelectWorkspace);
            Views.Add(viewAlbumsWorkspace);
 
            Views.Add(adminWorkspace);
            
            SetActiveWorkspace(aboutWorkspace);

 
What I want to be able to do is, within my Login ViewModel be able to refresh the MainWindowViewModel so that if anyone logs in as an Admin User, the additional Admin tab is displayed. I am using the following code to display my Tab View within the Main Window:
 

 
<DataTemplate DataType="{x:Type CinchV2:WorkspaceData}">
    		<AdornerDecorator>
    			<Border HorizontalAlignment="Stretch" 
    				VerticalAlignment="Stretch" 
    				CinchV2:NavProps.ViewCreator="{Binding}"/>
    		</AdornerDecorator>
    	</DataTemplate>

 
In my LoginViewModel I have the following code which executes when the button is pressed:
 

private void ExecuteLoginCommand(EventToCommandArgs args)
        {
            DataAccess dataAccessClass = new DataAccess();
            Boolean loginResult = dataAccessClass.loginResult(userName.DataValue,password.DataValue);
            
            //Boolean loginResult = new DataAccess

            if (loginResult)
            {
                string userAccessLevel = dataAccessClass.getUserAccess(userName.DataValue);
                this.loginResult = "Successful login";
                ConfigurationManager.AppSettings.Set("UserName", userName.DataValue);
                //CinchBootStrapper.Initialise(new List<Assembly> { typeof(App).Assembly });
                //Cinch.ViewResolver
                
                //NotifyPropertyChanged("MainWindowViewModel");
                //ViewModelRepository.Instance.Resolver
                ViewResolver.CreateView("MainWindowViewModel");
                //ConfigurationManager.AppSettings.Set("UserType", "admin");         
            }
            else
            {
                this.loginResult = "Unsuccessful login, please try again";
            }
        }

 
Can anyone offer me an idea as to how to get from this stage so that the user can see the control?

Jul 6, 2012 at 7:59 AM
Edited Jul 6, 2012 at 7:59 AM

Hello Scrappy,

you could use the mediator to notify your MainWindowViewModel about the login.

In your MainWindowViewModel you can register a listener to mediator events like that. LoginHandler is the methode which handles the event.

Mediator.Instance.RegisterHandler<string>("UserLogin", x => LoginHandler(x)); 

This should go into your LoginViewModel. This fires the event:

Mediator.Instance.NotifyColleagues<string>("UserLogin", "Administrator");
Coordinator
Jul 12, 2012 at 5:12 PM

Scrappy 

 

As HelmutE says using the Mediator within Cinch is the way to go for this, simply do what HelmutE suggests, and in you mediator hander (in MainWindowViewModel ) you can create a new workspace when you recieve the message telling you an Admin user has logged in

Jul 13, 2012 at 8:42 AM

Knew it'd be something simple! Thank-you guys, help was really appreciated!

Coordinator
Jul 16, 2012 at 11:35 AM

NO worries man