none
ElementHost's black border problem

    Question

  • Hi,

     

    I have a winform application that hosts WPF controls using ElementHost.

    The ElementHost's AllowTransparency is set to True, and BackColor=Transparent.

     

    But when the form's OnPaint is called and the area behind the ElementHost is repainted than the elementHost turns to be not transparent again - unless I set its visibility to false and than true again (Refresh won't work).

     

    Also have the problem when the ElementHost is inside a WinForm panel which is not visible and set the panel to be visible again.

     

    Would appreciate the help!

    Thanks.

    Monday, February 04, 2008 5:05 PM

All replies

  • You can use ElementHost.BackColorTransparent property to do this. Here is the example. I'm using Visual Studio 2008 with .NET Framework 3.5.

     

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();

                this.BackColor = Color.Red;

                System.Windows.Controls.Button btn = new System.Windows.Controls.Button()
                {
                    Width = 100,
                    Height = 30
                };
                System.Windows.Controls.Border bdr = new System.Windows.Controls.Border()
                {
                    BorderBrush = System.Windows.Media.Brushes.Blue,
                    BorderThickness = new System.Windows.Thickness(3),
                    Child = btn
                };
                ElementHost host = new ElementHost()
                {
                    BackColorTransparent = true,
                    Location = new Point(30, 30),
                    Size = new Size(200, 200),
                    Child = bdr
                };

                this.Controls.Add(host);
            }
        }

     

    Best Regards,

    Wei Zhou

    Wednesday, February 06, 2008 6:28 AM
    Moderator
  • Hi,

    I had set the BackColorTransparent=True (not AllowTransparency as I wrote)

    and still has the bug.

     

    Wednesday, February 06, 2008 5:00 PM
  • Hi,

    i have the same problem and no solution for it.

    WinForm-Transparent and parts of the ElementHost should be also transparent.

    Ralf

     

    Monday, February 25, 2008 3:29 PM
  • Hi,

    Just set the elementshost's MarginProperty like this:



    elementHost1.Margin = new Padding(0, 0, 0, 0);
    


    Make sure that none of your visual objects overlaps your elementshost's left border.




    cerbium

    Tuesday, February 02, 2010 12:54 PM