我注意到,当覆盖System.
Windows.Window OnRender方法无法绘制到屏幕.我确定有一个很好的理由,但无法找到解释.
原文链接:https://www.f2er.com/windows/370654.html以下代码演示如下:
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace WpfApplication1 { public partial class Window1 : Window { Pen pen = new Pen(); public Window1() { InitializeComponent(); pen.Brush = Brushes.Black; } protected override void OnRender(DrawingContext dc) { base.OnRender(dc); dc.DrawRectangle(Brushes.Black,pen,new Rect(0,600,400)); dc.DrawEllipse(Brushes.Green,new Point(300,300),50,50); } } }
在FrameworkElement中替换绘图逻辑(然后将元素设置为窗口的内容)工作正常.
谢谢,
丹尼