Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
We have a rather big Windows Forms Application.
Now we want to gradually develop new features in WPF windows, within our Windows Forms Application.
Everything works fine, except that the WPF windows are always on top of the older WinForm windows.
And it is impossible to drag an activated WinForm window on top of a WPF window.
Both are not modal forms, so our users need to be able to put one WinForm on top of the WPF window, switching between the WinForm and the WPF window.

I suspect it has something to do with the MdiParent I have in my Windows Forms Application and the fact that you can not set a WPF window to that MdiParent??

Any help would be much appreciated!

Thanks,
Sarah

What I have tried:

This is how a WPF window, in this example frmArchiefonderdeel, is called:

Dim oFrmArchiefOnderdeel As New frmArchiefonderdeel With {.oSharedData = oSharedData}
   oFrmArchiefOnderdeel.Show(Me)

<Extension()> Public Sub Show(wn As Windows.Window, owner As Windows.Forms.Form)
   BMFUtility.SetOwner(owner, wn)
   ElementHost.EnableModelessKeyboardInterop(wn)

   AddHandler wn.Closed, AddressOf WindowClosed

   wn.ShowInTaskbar = False
   wn.Show()
End Sub

Public Shared Sub SetOwner(owner As System.Windows.Forms.Form, wpfWindow As System.Windows.Window)
   Dim helper As New WindowInteropHelper(wpfWindow)
   helper.Owner = owner.Handle
End Sub


And this is how an older WinForm, in this example frmBDGMonitor, is called:
Dim oFrmBDGMonitor As frmBDGMonitor
oFrmBDGMonitor = New frmBDGMonitor
oFrmBDGMonitor.ShowInTaskbar = False
oFrmBDGMonitor.MdiParent = Me
oFrmBDGMonitor.Show()
Posted
Updated 24-Jan-18 6:43am

1 solution

Two important notes here:

1. The WPF/WinForm interop is very touchy - it can be difficult to get the complete expected behavior.

2. WPF does not support MDI so you may incompatibility issues trying to use WPF interop with MDI.

What I would recommend from a migration standpoint is to build the new core pieces to the application in WPF and use the WinForms interop. MDI itself has kind of been shunned from the UI perspective too, so I'd jump on board with that trend anyway.

The other problem is, if you're not building your core in WPF first there's going to be a slew of conflict and redundancy when you start getting through your migration.

In addition to that, during the migration you should be adapting modern composite application development so your shells and frameworks should be WPF based.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900