找不到视图模型的视图

时间:2014-04-07 09:00:35

标签: c# wpf mvvm caliburn.micro

我无法使用 Caliburn.Micro 找到任何观看次数。引导程序启动,但随后出现一个通用窗口,即 ShellViewModel 没有任何视图,即使有 ShellView.xaml 。怎么办?

引导程序

public sealed class AppBootstrapper : BootstrapperBase
{


    private IKernel _kernel;

    #region Bootstrapper

    public AppBootstrapper()
    {
        Start();
    }

    protected override void Configure()
    {
        _kernel = new StandardKernel();
        _kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
        _kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
        _kernel.Bind<IShell>().To<ShellViewModel>();
    }

    protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
    {
        DisplayRootViewFor(typeof (IShell));
    }

    protected override void OnExit(object sender, EventArgs e)
    {
        _kernel.Dispose();
        base.OnExit(sender, e);
    }

    protected override object GetInstance(Type serviceType, string key)
    {
        if (serviceType != null) {
            return _kernel.Get(serviceType);
        }

        throw new ArgumentNullException("serviceType");
    }

    protected override IEnumerable<object> GetAllInstances(Type serviceType)
    {
        return _kernel.GetAll(serviceType);
    }

    protected override void BuildUp(object instance)
    {
        _kernel.Inject(instance);
    }

    #endregion

    }
}

ShellViewModel

 public sealed class ShellViewModel : Screen, IShell
{

    public ShellViewModel()
    {
        DisplayName = "Hello";
    }

}

1 个答案:

答案 0 :(得分:2)

您可能需要使用SelectAssemblies的覆盖来告诉CM“.dll”用于视图和视图模型的位置。否则它永远找不到它们。我通常也会将它用于我的项目,它应该可以解决你的问题。