Answered by:
ElementHost flickers black borders on resize

Question
-
I googled about the issue. Also read this, this and this SO questions. I tried some of those things but nothing seemed to help.
Consider the following simple example code. It's just an empty ElementHost inside a WinForm (no WPF control inside):
using System.Windows.Forms; using System.Windows.Forms.Integration; namespace WindowsFormsApplication15 { public partial class Form1 : Form { public Form1() { InitializeComponent(); ElementHost host = new ElementHost(); host.Dock = DockStyle.Fill; this.Controls.Add(host); } } }
When you resize the form, you can see two black edges at the form border:
Please, ¿someone could give a working solution over my example to fix this issue?
- Edited by Daniel Peñalba Thursday, March 26, 2015 4:29 PM
Thursday, March 26, 2015 2:46 PM
Answers
-
Did you read the rest of my reply? Then read it again:
This is a known issue/bug (probably without any known solution): https://social.msdn.microsoft.com/Forums/vstudio/en-US/2df575eb-5428-49e6-b287-b4d830b4ccf4/black-background-on-resizing-element-host
If it bothers you that much and you cannot get rid of it using any of the solution(s) from above, then I am afraid that you will have to get rid of the ElementHost and only use Windows Forms control on your Form. Or switch/convert your application to WPF.
Please remember to mark all helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
- Proposed as answer by Magnus (MM8)MVP Friday, March 27, 2015 11:42 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
Thursday, March 26, 2015 3:42 PM -
Errrm..
It's the elementhost which is the problem.
That's windows forms.
So if you're pointing fingers it's not actually wpf is the thing to point at.
They render inherently differently though.
It's like trying to mix oil and water.
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
Thursday, March 26, 2015 8:35 PM
All replies
-
Please refer to the following thread for a possible solution for this behaviour:
http://stackoverflow.com/questions/6501890/elementhost-layout-problems
http://stackoverflow.com/questions/4122562/black-background-on-resizing-elementhostThis is a known issue/bug though: https://social.msdn.microsoft.com/Forums/vstudio/en-US/2df575eb-5428-49e6-b287-b4d830b4ccf4/black-background-on-resizing-element-host
If it bothers you that much and you cannot get rid of it using any of the solution(s) from above, then I am afraid that you will have to get rid of the ElementHost and only use Windows Forms control on your Form. Or switch/convert your application to WPF.
Please remember to mark all helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
- Edited by Magnus (MM8)MVP Thursday, March 26, 2015 3:00 PM
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
- Unproposed as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
Thursday, March 26, 2015 2:57 PM -
Hi Magnus, in my first line, I said that I checked those SO threads, but nothing helped. So I'm afraid that your answer is not useful for me.Thursday, March 26, 2015 3:15 PM
-
Did you read the rest of my reply? Then read it again:
This is a known issue/bug (probably without any known solution): https://social.msdn.microsoft.com/Forums/vstudio/en-US/2df575eb-5428-49e6-b287-b4d830b4ccf4/black-background-on-resizing-element-host
If it bothers you that much and you cannot get rid of it using any of the solution(s) from above, then I am afraid that you will have to get rid of the ElementHost and only use Windows Forms control on your Form. Or switch/convert your application to WPF.
Please remember to mark all helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
- Proposed as answer by Magnus (MM8)MVP Friday, March 27, 2015 11:42 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
Thursday, March 26, 2015 3:42 PM -
Magnus, thanks for your reply.
Of course, I read the rest of your reply. As you can imagine, if I'm asking, is because IS NOT a solution for me to get rid of the ElementHost. I do need to use a WPF control, and my codebase is WinForms.
Also isn't a solution to convert about 1M LOC of my code base to WPF right now.
So I'm afraid that I will have to learn how to live with you helpful answer and a buggy technology such as WPF.
Yours Truly,
Daniel
Thursday, March 26, 2015 3:55 PM -
Errrm..
It's the elementhost which is the problem.
That's windows forms.
So if you're pointing fingers it's not actually wpf is the thing to point at.
They render inherently differently though.
It's like trying to mix oil and water.
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 4, 2015 5:10 AM
Thursday, March 26, 2015 8:35 PM