我刚刚开始使用Caliburn.Micro。
我试图引导我的简单示例解决方案,将ShellView(用户控件)放置在Test.App程序集中,而将ShellViewModel放置在Test.ViewModel程序集中。
我得到的是一个窗口,上面显示着以下文本:“找不到 Caliburn.Test.ViewModel.ShellViewModel 的视图”。
但如果我将ViewModel移动到.App程序集中,它就可以完美地工作。
这是Caliburn.Micro.Test程序集(可执行文件)中的Bootstraper:
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 组件(类库)中的 ViewModel:
namespace Caliburn.Micro.Test.ViewModel
{
public interface IShell
{
}
public class ShellViewModel : IShell
{
}
}
请问您能帮我解决问题吗?谢谢!:D
SelectAssemblies
方法?你需要提供包含视图的所有程序集给 CM。 - Charleh