سؤال

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.

UPDATE: 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.

WORKS:

private void frm_Configuracion_Load(object sender, EventArgs e)
    {
        /*ABM.frm_ABM_Banco_Sucursal banco_sucursal = new ABM.frm_ABM_Banco_Sucursal();
        panel1.Controls.Add(banco_sucursal);*/
    }

DONT WORK:

private void button3_Click(object sender, EventArgs e)
    {
        ABM.frm_ABM_Banco_Sucursal banco_sucursal = new ABM.frm_ABM_Banco_Sucursal();
        panel1.Controls.Add(banco_sucursal);
    }

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

I have encountered the same issue whereby my User Controls goes black when I click on a button to update my UI.

My User Controls were found in a TableLayoutPanel which does not contain the Property BackColorTransparent

In order to fix my issue, I have Refresh the Control. A code snippet is shown below:

foreach (Control subControls in this.MainTableLayoutPanel.Controls)
{
    foreach (Control control in subControls.Controls)
    {
        control.Refresh();
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top