4
votes

I read on MSDN and other websites (http://msdn.microsoft.com/en-us/library/ms751797.aspx and http://www.abhishekshukla.com/wpf/advanced-wpf-part-5-of-5-interop-in-windows-presentation-foundation/) that multilevel hybrid nesting of WPF and WinForms controls is not supported...

I have an application where a WPF window has a WindowsFormsHost where inside that a WPF control is hosted in an ElementHost. This WPF control contains other WinForms controls which are also in WinFormsHost. In short: WPF -> WinForms -> WPF -> WinForms.

So far I did not have any problems with that. After finding that small note on the MSDN page I'm wondering what exactly is not supported on that scenario, since it works for me.

Any ideas?

1
I did a ctrl+F of the word "hybrid" in the link you posted and didn't find that in the whole text. As an aside. Why are you doing that? Wouldn't it be preferrable to stay with WPF and drop useless winforms altogether?Federico Berasategui
I found the word hybrid in both links, in the MSDN link its in the box called Note which starts after 3 lines of introduction text. I'm doing this because I have to use legacy WinForms controls and want to develop all new stuff with WPF. Sometimes I need to put a new WPF control in a WinForms control, otherwise I have to develop new controls in WinForms which I definitly not want toHarry13
May I ask what are the winforms controls that you need?... Also, beside your need to use it, I really don't think its a good idea to intermix them both in such waysFederico Berasategui
I agree that's not a good idea but if you need to migrate step by step you have no other choice... The controls consist mostly of a combination of the following WinForms controls: Label, TextBox and PictureBoxHarry13
I cannot afford to convert everything at onceHarry13

1 Answers

2
votes

I would say the sense of "not supported" is "at your own risk". Most things will work, some things will not work, and it depends on your particular application whether the results will be acceptable. Or maybe you'll achieve results that are acceptable after some hacky workarounds are in place. MS aren't going to go out of there way to make it work.

I've worked with a project which contained a WinForms-WPF-WinForms nesting, and in general that worked - well enough to not rewrite the WinForms component. Focus is an issue - the nested control does not behave quite as you'd expect relating to focus gained/lost events, and keyboard focus can get stuck in the nested control. There may be a difference between whether the host element thinks it has focus and whether the contained control does. So I'd suggest focusing your testing around user input events and focus.