项目用例:实现登录界面(后台是远程JAVA服务),项目结构分层为BL(纯业务逻辑),UI(纯界面显示),

 (转载请注明来源:cnblogs coder-fang)

      MvvmLight (.net wpf)在项目中的应用

1. 首先在BL层引入 mvvm light包,之后会在BL在自动生成相关Locator,主要用于定位服务与ViewModel

        MvvmLight (.net wpf)在项目中的应用

2.我们在项目中创建了一个BaseViewModel,主要是存储共享服务与共享方法等:

 public class BaseVM : ViewModelBase
    {        
        //这是其它业务ViewModel可能会用到的服务类,全部在Locator中注册
        public ConfigService configService = ServiceLocator.Current.GetInstance<ConfigService>();
        public BackendService backendService = ServiceLocator.Current.GetInstance<BackendService>();
        public SysInfoService sysInfoService = ServiceLocator.Current.GetInstance<SysInfoService>();
        public ReadCardService readCardService = ServiceLocator.Current.GetInstance<ReadCardService>();
        
        public BaseVM()
        {

        }
       
        public void ShowMsg(String msg)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                Messenger.Default.Send<String>(msg, "ShowMessage");    
            });
            
        }
        public void SendMsg<T>(String token,T msg)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                Messenger.Default.Send<T>(msg, token);
            });
            
        }
    }
View Code

相关文章:

  • 2021-11-30
  • 2021-05-12
  • 2021-10-17
  • 2021-06-09
  • 2021-09-01
  • 2021-09-13
  • 2021-10-24
  • 2022-02-18
猜你喜欢
  • 2021-06-29
  • 2021-10-04
  • 2021-06-30
  • 2021-07-27
  • 2021-12-25
相关资源
相似解决方案