I’m using WPF MVVM to create a wizard in Excel 2007. The wizard code is based on this internationalized wizard.
Because WPF must be contained within an ElementHost all of my views are user controls, there is no App.xaml. Instead I create my WPF Application when the host WinForm is instantiated and bind my application resources dynamically as described here.
Private _wpfApplication As Windows.Application
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' WPF application instance
_wpfApplication = Application.Current()
If Application.Current Is Nothing Then
_wpfApplication = New Application()
End If
' Merge in your application resources.
_wpfApplication.Resources.MergedDictionaries.Add(TryCast(Application.LoadComponent(New Uri("Pitchbook.Excel.ChartWizard;Component/Themes/Generic.xaml", UriKind.Relative)), ResourceDictionary))
End Sub
Private Sub ChartWizard_Load(sender As Object, e As System.EventArgs) Handles Me.Load
' Create the WPF UserControl.
Dim uc As New MainWindow()
' Assign the WPF UserControl to the ElementHost control's child property.
ehMaster.Child = uc
End Sub
This works fine for the one module I have created so far. I have many modules to create and rather than having a WinForm container for each module I would really like to take the application to the next level by creating a composite application using Prism. I want to somehow have a generic WinForm that plays a similar role to App.xaml. When the user clicks a button on my ribbon I could launch this generic host WinForm bind the Shell.xaml to the ElementHost and use the bootstrapper to load the relevant modules based on some parameter or configuration that maps a ribbon button to a set of modules that should be loaded into the generic host container.
I’m struggling with the logic to do this and I wanted to get some opinions regarding the feasibility of this approach and if it is possible best ways it might be done. Basically I need to add the two layers in red to the existing composite application architecture.
http://www.patternjuggler.org/downloads/officecompositeapp.jpg
I think Igor Moochnick goes a long way to answering this question with the following article.
Office Applications via Prism of Unity