我创建了一个从BootstrapperBase派生的类,覆盖了OnStartup(),并调用了DisplayRootViewFor<AppViewModel>(),就像文档中的一样。
但是当我启动这个应用程序时,我得到了一个NullReferenceException on DisplayRooViewFor<AppViewModel>()
using Caliburn.Micro;
using MHBRestore.Logic;
using MHBRestore.UI.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace MHBRestore.UI
{
public class AppBootstrapper : BootstrapperBase
{
private SimpleContainer _container = new SimpleContainer();
public AppBootstrapper()
{
Initialize();
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<AppViewModel>();
}
protected override object GetInstance(Type service, string key)
{
return _container.GetInstance(service, key);
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
}
}发布于 2017-06-05 15:29:47
尝试重写Configure方法并注册视图模型类型:
public class AppBootstrapper : BootstrapperBase
{
private SimpleContainer _container = new SimpleContainer();
public AppBootstrapper()
{
Initialize();
}
protected override void Configure()
{
_container.Singleton<IWindowManager, WindowManager>();
_container.Singleton<IEventAggregator, EventAggregator>();
_container.RegisterPerRequest(typeof(AppViewModel), null, typeof(AppViewModel));
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<AppViewModel>();
}
protected override object GetInstance(Type service, string key)
{
return _container.GetInstance(service, key);
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
}https://stackoverflow.com/questions/44372190
复制相似问题