看起来Caliburn.Micro的WindowManager在WPF Windows上有问题,尽管该参数的类型已在Caliburn.Micro IoC中注册,但它具有构造函数参数。除了在构造函数中使用臭味服务定位器IoC.Get(Of T)之外,是否有更好的方法将所需的参数放入Window中?

Namespace Views
  Class MainWindowView
    Private _eventAggregator As IEventAggregator
    Public Sub New(eventAggregator As IEventAggregator)
      _eventAggregator = eventAggregator
    End Sub
  End Class
End Namespace

Sub ShowMainWindowView()
  'Everything is correctly registered in Ioc...
  Dim windowManager As New WindowManager
  Dim viewModel As New MainWindowViewModel
  windowManager.ShowDialog(viewModel)
  'Exception is thrown about absence of parameterless constructor of MainWindowView
End Sub

最佳答案

我试图在新的,清晰的项目中再次重现此问题,并且它可以工作-仅需要在IoC容器中注册 View 类型(Window),WindowManager会自动将所需的依赖项注入(inject) View 的构造函数中。

关于wpf - Caliburn.Micro WindowManager和Window构造函数参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42780948/

10-12 12:49