使用Cinch在WPF中加载系统后添加工作区 [英] Add a workspace after system load in WPF with Cinch

查看:143
本文介绍了使用Cinch在WPF中加载系统后添加工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiya,

我正在使用Cinch框架来构建我的应用程序,目前有以下代码在MainWindowViewModel中运行,以将项目添加到主窗口的工作区中:

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



我想要做的是,在我的Login ViewModel中能够刷新MainWindowViewModel,这样,如果任何人以Admin用户身份登录,就会显示附加的Admin选项卡.我正在使用以下代码在主窗口中显示我的标签视图:



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>



在我的LoginViewModel中,我有以下代码,当按下按钮时会执行以下代码:



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?

推荐答案

您可以发送带有Mediator.Instance.NotifyColleagues的消息
方法.

当然,在MainViewModel中,您必须具有这样的方法:
You could send a message with the Mediator.Instance.NotifyColleagues
method.

Of course in your MainViewModel you have to have a method like this:
[MediatorMessageSink("LoginMessage")]
private void LoginMessageReceived(bool adminLoggedIn)
{
  // do something here to the visibility of your admin tab
}



发送使用以下方式完成:



Sending is done with:

Mediator.Instance.NotifyColleagues("LoginMessage", adminLoggedIn);



希望这会有所帮助.



Hope this helps.


这篇关于使用Cinch在WPF中加载系统后添加工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆