Andres Andres - 1 year ago 150
C# Question

Black backcolor in Controls when it was set to transparent

I´m having an issue with WPF elementHost backcolors. I have a winform that loads in a panel an UserControl(Winform). In that user control I have two panels, inside of each of them, there is an elementHost that hosts a WPF usercontrol.

The picture can be more helpful:
enter image description here

As you can see, the backcolor of each of them is BLACK while the element should be displayed like this:

enter image description here

I notice that this happened when I load other UserControls in panels. I need to know how to fix this.

Each elementHost has its backcolor set to Transparent and BackColorTransparent in True.
Also, I tried to change the backcolor in runtime, but still the same problem.

Ok guys, I notice that if I load the UserControl in the panel in the event Load of the Form, the elementHost loads correctly. But, if I load the UserControl in the panel in a button click event, I´m getting that black backcolor.


private void frm_Configuracion_Load(object sender, EventArgs e)
/*ABM.frm_ABM_Banco_Sucursal banco_sucursal = new ABM.frm_ABM_Banco_Sucursal();


private void button3_Click(object sender, EventArgs e)
ABM.frm_ABM_Banco_Sucursal banco_sucursal = new ABM.frm_ABM_Banco_Sucursal();

Obviously, using the Load event would be the solution just if I´m using one UserControl, but I´m not.

Answer Source

Ok, this is how I solve it:

I put this code in the Load() event of every UserControl:

elementHost.BackColorTransparent = true;

Being elementHost every elementHost element that is having that trouble.

Its curious, but that property was set in true in design time using the visual designer, I think something could mess it up during execution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download