Question

I'm using the WindowsFormsHost to add a Windows Forms control in my WPF application, but I realise that WinForms controls cannot have transparent backgrounds without setting the style as in here How to: Give Your Control a Transparent Background. How would this be done in WPF?

BTW, I'm using C# and .net 4.0.

Thanks.

Was it helpful?

Solution

I don't think you can do this. The link you provided is really about being able to set the BackColor to Transparent. When that happens the WinForms control (in its paint background handling) gets the Parent Control and calls its PaintBackground and Paint methods. While your control will have a parent - the control that the WindowsFormsHost will create - that control will not and so there will be nothing to draw the background. In a Win32 world one might set the WS_EX_TRANSPARENT bit but that introduces all sorts of issues and I suspect it may not even work based on how WPF works. I would check out the MSDN topics (e.g. Technology Regions Overview and WindowsFormsHost interop) discussing the various air space issues with interop between WPF and other technologies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top