我想做一个自定义网格控件,因为默认不支持显示网格线。我为此找到了一个 wpf 解决方案,但是 winrt 缺少 wpf 支持的一些功能。wpf 解决方案中的代码是这样的:
protected override void OnRender(DrawingContext dc)
{
if (ShowCustomGridLines)
{
foreach (var rowDefinition in RowDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(0, rowDefinition.Offset), new Point(ActualWidth, rowDefinition.Offset));
}
foreach (var columnDefinition in ColumnDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(columnDefinition.Offset, 0), new Point(columnDefinition.Offset, ActualHeight));
}
dc.DrawRectangle(Brushes.Transparent, new Pen(GridLineBrush, GridLineThickness), new Rect(0, 0, ActualWidth, ActualHeight));
}
base.OnRender(dc);
}
但是我不能覆盖 onrender 方法,并且 winrt 中没有绘图上下文。那么我怎样才能在我的网格上绘制网格线呢?谢谢您的帮助!