2017-01-02 90 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

相關問題