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!
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
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