2

For start I will say that I googled this issue, and there are a lot of topic about that, but none of those helped me to solved my problem (For example: ThisPost, Or This, Or this)

So the problem is that I have a Windows Form application, that host a WPF application. I have an ElementHost object, that contains the WPF control as a child. when I use the .Show method, I have black flicker for 1 or 2 second, and then I see the content of my wpf.

I try to play with the visibility or to put different background, or set empty bounds before, but none of those helped me. if anyone have different solution, please share it with me.

Community
  • 1
  • 1
Shaiba7
  • 159
  • 6
  • Could you provide some code? I'm trying to reproduce your problem by creating simple wpf control and hosting it in winforms using ElementHost and I'm not having any flickering problems. – Umriyaev Jul 12 '15 at 08:14
  • Hi, Thanks for trying to work on it, i tried to create a new solution with an example of my issue, but i wasn't able to reproduce it yet (look like it work fine), i guess the problem come from the heavy loading of the WPF control or the WinForm, As soon as i able to reproduce the problem i will upload my code. – Shaiba7 Jul 12 '15 at 08:44

1 Answers1

2

I had the same issue as you and none of the other answers I could find actually worked and so after a long time of troubleshooting the issue. I found an answer.

If you build a class extending from Element Host and in the initial constructor. You can set a Load Event for the Host Container. The Host Container is the panel that the Element Hosts Child is being displayed on top of. From there, just set the Host Containers background color to being of the Element Hosts Parents background color.

Like this

using System.Windows;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Media;
public class MyElementHost : ElementHost
{
   public MyElementHost()
    {
        this.HostContainer.Loaded += new RoutedEventHandler(HostPanelLoad);
    }

    public void HostPanelLoad(object sender, RoutedEventArgs e)
    {
        System.Drawing.Color parentColor = this.Parent.BackColor;
        this.HostContainer.Background = new SolidColorBrush(Color.FromArgb(parentColor.A, parentColor.R, parentColor.G, parentColor.B));
    }
}
Vash
  • 332
  • 3
  • 14