我剛開始使用Caliburn.Micro。Caliburn.Micro無法與來自不同程序集的View和ViewModel相匹配
我想引導我簡單的示例解決方案將ShellView(usercontrol)放置在Test.App程序集和Test.ViewModel程序集中的ShellViewModel中。
我得到的是帶有以下文本的窗口:「無法找到Caliburn.Test.ViewModel.ShellViewModel的視圖」。
但是,如果我將ViewModel移動到.App程序集,它可以很好地工作。
這是Bootstraper在Caliburn.Micro.Test組件(可執行文件):
namespace Caliburn.Micro.Test
{
public class AppBootstrapper : BootstrapperBase
{
SimpleContainer container;
public AppBootstrapper()
{
this.Start();
}
protected override void Configure()
{
container = new SimpleContainer();
this.container.Singleton<IWindowManager, WindowManager>();
this.container.Singleton<IEventAggregator, EventAggregator>();
this.container.PerRequest<IShell, ShellViewModel>();
}
protected override object GetInstance(Type service, string key)
{
var instance = this.container.GetInstance(service, key);
if (instance != null)
return instance;
throw new InvalidOperationException("Could not locate any instances.");
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return this.container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
this.container.BuildUp(instance);
}
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
this.DisplayRootViewFor<IShell>();
}
protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
{
var assemblies = new List<Assembly>()
{
Assembly.GetExecutingAssembly(),
Assembly.Load("Caliburn.Micro.Test.ViewModel"),
};
return assemblies;
}
}
}
這是我在Caliburn.Micro.Test.ViewModel裝配視圖模型(類庫):
namespace Caliburn.Micro.Test.ViewModel
{
public interface IShell
{
}
public class ShellViewModel : IShell
{
}
}
你能幫我解決我的問題嗎? 謝謝! :D
你是否重寫了'SelectAssemblies'?你需要提供CM包含視圖的所有程序集 – Charleh