PRISM + Windows Forms Controls

Topics: Prism v4 - WPF 4
Feb 28, 2011 at 3:29 PM


I have a view where I host a windows forms control using WindowsFormsHost. The control needs parameters which are provided by the ViewModel, and are made available through an EventAggregator event (= not set on init). If the needed paramter values are set, a method on the windows forms control must be called to get it working.

So acutally I have a method in my _View_ to set/call the Windows Form control. The problem is, that the needed parameters are not available immediatelly from the ViewModel, but when the event subscription in the VM fires the specific event which brings the data with it. Right after that I have to call the View's method. But how to know inside the View when the needed data is available? 

I think thats a little bit against PRISM/MVVM concepts, but how to work around that?


Feb 28, 2011 at 7:22 PM


You might find the Interaction Request mechanisms useful to achieve your scenario. You can read about them in the Advanced MVVM Scenarios chapter in the Prism MSDN documentation.

Additionally, you might find the MVVM QuickStart useful, as it portrays the use of such mechanisms in a sample application.

I hope you find this helpful.

Guido Leandro Maliandi

Mar 3, 2011 at 3:16 PM
Edited Mar 3, 2011 at 3:27 PM

Thanks Guido, in the end it got it working without using Interaction Request. Just used a controller to keep the viewmodels synchronized and passing the needed data. 

Now I just have one problem left: The view which contains a windows form control is just loaded when an item in my application is opened (button click). This needs some time on the first time (part creation shared, keepalive true), since the Windows Forms Control is pretty complex. Is it possible to preload that view (which contains the winforms control) invisible/in background on application startup to make even the first item open action smooth and without wait time? Is that possible?


Update: I've tried to create a instance of the winforms control in the Module Initialize() method, and export it using Mef. In the View's default constructor I import the control and add it to the WindowsFormsHost. Now it slows down the app startup, but seems to work.. Is that the right approach, or is there a better way??

Mar 3, 2011 at 4:16 PM
Edited Mar 18, 2011 at 3:21 PM


There is no guidance in Prism regarding how to manage the preload of components that are slow to load. The approach you've mentioned seems a valid possibility to address your requirement.

You might find the following thread useful, where a similar concern is treated (related to a whole module which has a long initialization time):

LoadModule Unity WPF

I hope you find this helpful.

Guido Leandro Maliandi