相关疑难解决方法(0)

使用Caliburn Micro将EventAggregator注入ViewModel

从EventAggregator上的Caliburn Micro文档中提取:

// Creating the EventAggregator as a singleton.
public class Bootstrapper : BootstrapperBase {
    private readonly SimpleContainer _container =
        new SimpleContainer();

     // ... Other Bootstrapper Config

    protected override void Configure(){
        _container.Singleton<IEventAggregator, EventAggregator>();
    }

    // ... Other Bootstrapper Config
}

// Acquiring the EventAggregator in a viewModel.
public class FooViewModel {
    private readonly IEventAggregator _eventAggregator;

    public FooViewModel(IEventAggregator eventAggregator) {
        _eventAggregator = eventAggregator;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以问题是如何让Bootstrapper创建的EA实例注入你的虚拟机?

var svm = new SomeViewModel(?);

我尝试使用Caliburn.Micro.IoC.Get方法,但这不起作用......

c# mvvm caliburn.micro

1
推荐指数
1
解决办法
2720
查看次数

标签 统计

c# ×1

caliburn.micro ×1

mvvm ×1