0
간단한 응용 프로그램을 만들어야하는데, 여기서는 초기화 중에 무언가가 발생합니다. MainViewModel
내 코드를 실행하려고하면부트 스트 래퍼 DisplayRootFor <MV>() 예외 : 매개 변수가없는 생성자가 없습니다.
는 예외는 AppBootstrapper
에 라인 DisplayRootViewFor<MainViewModel>();
에 발생
유형 'System.MissingMethodException'의 예외가 mscorlib.dll에서 발생했지만 사용자 코드에서 처리되지 않은추가 정보 :이 객체에 대해 정의 된 매개 변수없는 생성자가 없습니다.
스트 래퍼 :
using System;
using Ninject;
using Caliburn.Micro;
namespace ChartsDisplayer2016
{
public class AppBootstrapper : BootstrapperBase
{
private IKernel kernel;
public AppBootstrapper()
{
Initialize();
}
protected override void Configure()
{
kernel = new StandardKernel();
kernel.Load(AppDomain.CurrentDomain.GetAssemblies());
kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
}
protected override void BuildUp(object instance)
{
kernel.Inject(instance);
}
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
base.OnStartup(sender, e);
DisplayRootViewFor<MainViewModel>();
}
}
}
MainViewModel :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChartsDisplayer2016.Core.Charts.ViewModels;
using Caliburn.Micro;
namespace ChartsDisplayer2016.Core.Main.ViewModels
{
public class MainViewModel: Conductor<Screen>.Collection.OneActive
{
private readonly IEventAggregator eventAggregator;
private readonly IWindowManager windowManager;
MainViewModel()
{
//something important;
}
MainViewModel(IEventAggregator eventAggregator,
IWindowManager windowManager)
{
this.eventAggregator = eventAggregator;
this.eventAggregator.Subscribe(this);
this.windowManager = windowManager;
//something important
}
}
}
MAINVIEW :
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Class="ChartsDisplayer2016.Core.Main.Views.MainView"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
이 예외를 제거하려면 어떻게해야합니까?
편집 : public
답장을 보내 주셔서 감사합니다. 불행히도'MainViewModel''' public'을 작동시키지 못했습니다 - 예외는 여전히 동일합니다. –
생성자를 공개로 설정 했습니까? –
아니, 나는하지 않았다. 이제 공공 생성자와 함께 잘 작동합니다. 고맙습니다. :) –