wpf - Caliburn.Micro WindowManager 和 Window 构造函数参数

标签 wpf mvvm caliburn.micro

看起来 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 类型(窗口),并且 WindowManager 会自动在 View 的构造函数中注入(inject)所需的依赖项。

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

相关文章:

c# - 为 ItemsControl 的每一项创建一个 ViewModel

c# - 绑定(bind)到 UserControl 中的 DataGrid ItemSsource

caliburn.micro - 如何使用 Caliburn Micro 的简单容器注册特定的单例实例?

c# - WPF MVVM模式中两个 View 之间的共享 View 模型

c# - 在自定义控件上使用命令

c# - 在 WPF 中实现暂停

c# - Entity Framework 中应该如何管理一对多关系?

c# - WPF动画不流畅

xaml - ResourceLoader 在 ViewModel 中返​​回错误的语言

c# - 如何绑定(bind)到 WPF 应用程序中的 subview 模型属性?