2012-03-27 47 views
0

任何人都可以提出的方法,将允许我从ElementHost中的WPF元素更改主机WinForm的属性吗?从ViewModel绑定到ElementHost更改主机WinForm属性

Prism Stack

我必须使用绑定到一个ElementHost的棱镜的MVVM应用程序。我想更改WinForm标题,调整WinForm的大小并关闭我的ViewModel中的WinForm。

我明白从this article中描述的WPF复合控件接收数据,但我无法看到这将在ViewModel中如何工作。

应用程序是WinForm ChartWizardViewModel是ViewModel我想更改应用程序的属性。 其他一切都是棱镜架构。壳,引导程序等。

Public Class App 
Public Sub New(ByVal modulesToLoad As List(Of String)) 
     ' This call is required by the designer. 
     InitializeComponent() 

     If Application.Current Is Nothing Then 
      Dim wpfAppAdapter As New WpfApplicationAdapter 
     End If 

     ' Load the application modules 
     Dim formBootstrapper As New Bootstrapper(modulesToLoad) 
     formBootstrapper.Run() 

     ' Get the current instance of shell and bind it to the ElementHost 
     Dim shellElement = formBootstrapper.Container.Resolve(Of Shell)() 
     ehMaster.Child = shellElement 
End Sub 
End Class 

Public NotInheritable Class Bootstrapper 
Inherits UnityBootstrapper 

Private _modulesToLoad As List(Of String) ' The modules that we want to load 

Public Sub New(ByVal modulesToLoad As List(Of String)) 
    _modulesToLoad = modulesToLoad 
End Sub 

Protected Overrides Function CreateShell() As DependencyObject 
    Dim shell = Container.Resolve(Of Shell)() 
    Return shell 
End Function 

Protected Overrides Function GetModuleCatalog() As IModuleCatalog 
    Dim catalog As ModuleCatalog = New ConfigurationModuleCatalog() 
    For Each moduleToLoad As String In _modulesToLoad 
     Select Case StringHelper.CleanString(moduleToLoad) 
      Case "chartwizardmodule" 
       catalog.AddModule(GetType(ChartWizardModule)) 
     End Select 
    Next 
    Return catalog 
End Function 
End Class 

Public NotInheritable Class ChartWizardModule 
Implements IModule 

Private ReadOnly regionManager As IRegionManager 

Public Sub Initialize() Implements IModule.Initialize 
    regionManager.RegisterViewWithRegion("MainRegion", GetType(MainWindow)) 
End Sub 

Public Sub New(regionManager As IRegionManager) 
    Me.regionManager = regionManager 
End Sub 
End Class 

Partial Public Class MainWindow 
Private _objChartWizardViewModel As ChartWizardViewModel ' The chart wizard base view model that controls the rest of the views 

Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
    Dim objChartWizardViewModel As New ChartWizardViewModel() 
    _objChartWizardViewModel = objChartWizardViewModel 
    ' Data Context for the Chart Wizard 
    Me.DataContext = _objChartWizardViewModel 
End Sub 
End Class 

Public Class ChartWizardViewModel 
Implements INotifyPropertyChanged 
    ' I need to change the properties of the WinForm (App) from here 
End Class 

回答