I noticed that when overriding the System.Windows.Window OnRender method fails to draw to the screen. I\'m sure there\'s a good reason for this but was unable to find the explan
I think, that Grid generate this problem. Becouse by default Window contains Grid element
The answer is given by Chales Petzold here.
His answer is 'don't know why', however a comment correctly suggests that setting the window's Background to transparent fixes the bug.
just as a check, does the snippet work with the dc.Draw...
lines removed (i.e. is it the act of overriding or the additional draw commands that cause the issue)?
I found a link that suggests that simply re-ordering the calls may solve the issue (i.e. doing the dc.Draw...
calls before calling base.OnRender(dc)
).
http://www.codeproject.com/Messages/3356653/Override-OnRender-class-inherits-frameworkelement.aspx
Actually, the Window paints itself, which among others is a rectangle for the background. Whatever is added in the OnRender is behind the background. Make the Background transparent and one can see what is behind it.
At least that is what I found out when using Button and OnRender. If I draw only within the button, nothing can be seen, because the button is drawn over it. But if the drawing extends beyond the button boundaries, anything outside can be seen.
Here an empty button is drawn over a yellow background. In the OnRender, I draw 2 black lines forming a cross. But only the parts of the line outside the button can be seen.
Very strange behavior of OnRender, indeed !