2012-03-27 3 views
0

Kann jemand Ansätze vorschlagen, die mir erlauben, die Eigenschaften eines Host-WinForm von einem WPF-Element in einem Element zu ändern?Ändern Host WinForm Eigenschaften von Viewmodel gebunden Element

Prism Stack

Ich habe eine MVVM Anwendung Prism verwendet, die zu einem Element gebunden ist. Ich mag den WinForm Titel ändern, die WinForm Größe und die WinForm aus meinem Ansichtsmodell zu schließen.

Ich verstehe, Empfangen von Daten von einem WPF Composite-Steuerelement in this article beschrieben, aber ich kann nicht sehen, wie das in einem ViewModel funktioniert.

App ist die WinForm ChartWizardViewModel ist das ViewModel Ich möchte die Eigenschaften von App ändern. Alles andere ist die Prism-Architektur. Shell, Bootstrapper usw.

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 

Antwort

Verwandte Themen