在Prism中使用带有非默认构造函数的视图

时间:2012-03-01 16:59:36

标签: vb.net mvvm unity-container vb.net-2010

下午 我现在正在努力研究如何创建一个需要非默认构造函数的视图(即需要输入的构造函数),

    Public Class Bootstrapper
    Inherits UnityBootstrapper

    Protected Overrides Function CreateShell() As System.Windows.DependencyObject
        Return New LogReader_Modular.Windows.Shell()
    End Function

    Protected Overrides Sub InitializeShell()
        MyBase.InitializeShell()
        Application.Current.MainWindow = CType(Me.Shell, Window)
        Application.Current.MainWindow.Show()
    End Sub

    Protected Overrides Sub ConfigureModuleCatalog()
        MyBase.ConfigureModuleCatalog()
        Dim moduleCatalog As ModuleCatalog = CType(Me.ModuleCatalog, ModuleCatalog)
        moduleCatalog.AddModule(GetType(GridModule))
    End Sub
....
....

Public Class GridModule
Implements IModule

Private ReadOnly regionManager As IRegionManager

Public Sub Initialize() Implements IModule.Initialize
    Try
        regionManager.RegisterViewWithRegion("MainDockingRegion", GetType(Views.GridModuleView))
    Catch ex As Exception
        Trace.WriteLine(String.Format("An Error occured the error was {0}", ex.ToString))
    End Try

End Sub

Public Sub New(ByVal regionManager As IRegionManager)
    Try
        Me.regionManager = regionManager
    Catch ex As Exception
        Trace.WriteLine(String.Format("An Error occured the error was {0}", ex.ToString))
    End Try

End Sub

结束班

我的问题是我想将构造函数值传递给GridModuleView,因为它在这里没有真正实例化,我真的不明白我如何传递值,任何对此的帮助都会受到赞赏,因为我已经现在已经看了好几天了。编辑*我想要传入的数据来自shell而不是视图,这就是我粘贴引导程序的原因 谢谢 汤姆。

1 个答案:

答案 0 :(得分:1)

您可以使用RegionManager.RegisterViewWithRegion(IRegionManager, String, Func(Object))方法而不是RegionManager.RegisterViewWithRegion(IRegionManager, String, Type)方法,然后将输入从shell传递给GridModule。