Add a workspace after system load in WPF with Cinch

Jul 5, 2012 at 2:47 PM

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);

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}">
    			<Border HorizontalAlignment="Stretch" 

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 });
                //ConfigurationManager.AppSettings.Set("UserType", "admin");         
                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 6:59 AM
Edited Jul 6, 2012 at 6: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");
Jul 12, 2012 at 4:12 PM



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 7:42 AM

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

Jul 16, 2012 at 10:35 AM

NO worries man