0
我想在WPF上的UserControl上繪製一個網格,所以我重寫OnCreate方法,但網格不會在我的UserControl上繪圖。 請幫助:)OnRender方法UserControl問題
public partial class FightField : UserControl
{
public FightField()
{
InitializeComponent();
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
var pen = new Pen(Brushes.Black, 1);
for (var i = 1; i < 10; i++)
{
drawingContext.DrawLine(pen, new Point(this.Height/10 * i, 0), new Point(this.Height/10 * i, this.Width));
drawingContext.DrawLine(pen, new Point(this.Width/10 * i, 0), new Point(this.Width/10 * i, this.Height));
}
}
}
不客氣! –