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>
この例外を取り除くにはどうすればよいですか?
EDIT:public
あなたの答えをありがとう。残念ながら、 'MainViewModel''' public'を動作させなかった - 例外は同じです。 –
コンストラクタをパブリックにしましたか? –
いいえ、私はしませんでした。今は公共のコンストラクタでうまく動作します。どうもありがとうございました :) –