2017-01-02 92 views
2

我一直在尝试这一段时间,我有一些问题。我有一个项目动态加载1个或更多的DLL,我不能让视图绑定工作。Caliburn Micro - 在单独的DLL中查看&viewmodel

我已经覆盖了SelectAssemblies方法,例如:

protected override IEnumerable<Assembly> SelectAssemblies() 
    { 
     string[] AppFolders = Directory.GetDirectories(Config.AppsFolder); 

     List<Assembly> assemblies = new List<Assembly>(); 
     assemblies.Add(Assembly.GetExecutingAssembly()); 

     foreach (string f in AppFolders) 
     { 
      Assembly ass = Directory.GetFiles(f, "*.dll", SearchOption.AllDirectories).Select(Assembly.LoadFrom).SingleOrDefault(); 
      if (ass != null) 
      { 
       assemblies.Add(ass); 
      } 
     } 
     Apps = assemblies; 
     return assemblies; 
    } 

这按预期工作,然后我有它运行在一个按钮,点击它做的方法:

public void OpenApp(string appName) 
    { 
     //AppName should be the same as the dll. 

     string assName = string.Format("TabletApp.{0}", appName); 

     Assembly ass = AppBootstrapper.Apps.SingleOrDefault(x => x.GetAssemblyName() == assName); 

     if (ass != null) 
     { 
      dynamic vm = ass.CreateInstance(string.Format("TabletApp.{0}.ViewModels.{0}ViewModel", appName)); 
      IoC.Get<IWindowManager>().ShowDialog(vm); 
     } 
    } 

此发现viewmodel罚款,但是当我加载ExampleViewModel时,我得到错误“无法找到'ExampleView'的合同”。我也必须为基本程序集中的每个视图添加[导出(typeof(view)],因为我已经做了这个改变。看起来Caliburn micro自动停止了初始化视图

任何人都知道我在做什么,已经做了错误的?

回答

1

所以原来我没有做错什么,一路上我已经更新了我caliburn.micro到3.0.2的方式。事实证明,他们做了一个小的变化成为重大突发更新。我不会进入它完全这里除了要在需要更改引导程序指出它的GetInstance。

protected override object GetInstance(Type service, string key) 
    { 
     // Skip trying to instantiate views since MEF will throw an exception 
     if (typeof(UIElement).IsAssignableFrom(service)) 
      return null; 

     var contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(service) : key; 
     var exports = container.GetExportedValues<object>(contract); 

     if (exports.Any()) 
      return exports.First(); 

     throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract)); 
    } 

请仔细阅读以下麟k获取更多详细信息。

https://github.com/Caliburn-Micro/Caliburn.Micro/pull/339

相关问题