Why does overriding the WPF [removed] method fail to draw to the screen?

后端 未结 4 1787
面向向阳花
面向向阳花 2021-02-08 00:02

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

4条回答
  •  清酒与你
    2021-02-08 00:30

    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.

    enter image description here

    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 !

提交回复
热议问题