3 ms·
TLDR for whoever finds this and wants to fix their Winforms-on-WPF issues: - Clone [5] - Open the solution, compile, take the 2 DLLs Microsoft.DwayneNeed.dll
by olvy0 5y ago
TLDR for whoever finds this and wants to fix their Winforms-on-WPF issues:
- Clone [5]
- Open the solution, compile, take the 2 DLLs Microsoft.DwayneNeed.dll and Microsoft.DwayneNeed.Win32.dll
- Read [3] on how to integrate it into your application
Below are my random ramblings on my voyage through old & dusty corners of the internet, related to some old & dusty technologies that I have the pleasure to still use daily at $work.
At work my team has to support an old component written in winforms many years ago, a component that we'd like to deprecate but can't do it just yet. Almost our whole app has been converted to WPF except that component. Our app also has traditionally been an old, MDI based, desktop app, and we unfortunately currently have no plans or budget to make it into a web app, it would require a major overhaul for which our tiny team is unsuitable.
In addition to hundreds of legacy bugs, we have also been struggling with the Winforms sub-windows in the MDI hiding other MDI sub-windows in the WPF-based GUI, the so-called Airspace issue [0].
Apparently microsoft were planning to fix this for net 4.5 almost 10 years ago, and it was even included in the beta, but it got scrapped for some reason [6]. Or, maybe, the reason was that it was notoriously difficult thing to do [4] and they decided to scrap it due to basically trying to scrap WPF at the time.
We thought we found a partial solution here [1] called AirspaceFixer, that is also referenced by multiple StackOverflow answers. It works, but is more suitable for modal windows, such as the WebView component, and not for "islands" of winforms inside a WPF MDI application. That is because it relies on a snapshot technique that take a simple snapshot of the whole window, but if said window is occluded by another MDI window, this snapshotting will catch part of the other window and will look bad.
Also it doesn't actually update in the background, which also looks bad.
After looking around some more, I found that a guy named Dwayne Need, who once worked for Microsoft, actually developed a component which solves (or rather patches) the airspace problem.
He wrote a looonng blog post about the airspace problem, in 2013, a long and detailed treatise on why it's so extremely difficult to support Winforms inside WPF [4].
It also uses snapshotting, but a much more clever one, using clipping to identify which parts of the window to capture, and dealing with offscreen parts, and other stuff, and using some sophisticated low-level GDI+ hacks. I went over his code and the whole thing is a work of dark art for me...
His original code was on CodePlex, but when Microsoft closed this people moved it to github.
The major fork is in the MahApps project, here [2]. And it fixes a single null check.
Unfortunately it has zero documentation, but these guys added a simple How To here [3].
It's really trivial. Turns out you only need to compile 2 projects, the rest of the stuff in that solutions are demos, and integrating it is basically the XAML equivalent of a one-liner [3].
However a problem remained that their version didn't support high DPI and the winforms screen looked bad .
But! Some other guy (Mike) solved the DPI problem too, his fork is the OP above, also [5]. He mentioned it in passing on his blog [7] and also here [8].
That's all. I hope I haven't horribly misused HN or something by posting all of this, since this isn't "news" nor very interesting (well, I found all of this kind of interesting, but that might just be me), but it might benefit someone, someday, and it is somewhat related to hacking...
[0] https://adityaswami89.wordpress.com/2014/02/24/airspace-problem-wpf/ https://adityaswami89.wordpress.com/2014/02/24/airspace-prob...
[1] https://github.com/chris84948/AirspaceFixer https://github.com/chris84948/AirspaceFixer
[2] https://github.com/MahApps/Microsoft.DwayneNeed https://github.com/MahApps/Microsoft.DwayneNeed
[3] https://github.com/MahApps/MahApps.Metro/wiki/Why-is-WindowsFormsHost-or-WebBrowser-content-annoying-me%3F https://github.com/MahApps/MahApps.Metro/wiki/Why-is-Windows...
[4] https://dwayneneed.github.io/wpf/2013/02/26/mitigating-airspace-issues-in-wpf-applications.html https://dwayneneed.github.io/wpf/2013/02/26/mitigating-airsp...
[5] https://github.com/barbeque/DwayneNeed https://github.com/barbeque/DwayneNeed
[6] https://stackoverflow.com/a/42468667/585671 https://stackoverflow.com/a/42468667/585671
[7] https://nondisplayable.ca/2015/05/29/mahapps-metro-gotchas.html https://nondisplayable.ca/2015/05/29/mahapps-metro-gotchas.h...
[8] https://github.com/mike-ward/Markdown-Edit/issues/113 https://github.com/mike-ward/Markdown-Edit/issues/113