protected override void OnRender(DrawingContext dc) { if (ShowCustomGridLines) { if (GridLinesVisibility == GridLinesVisibilityEnum.Both) { foreach (var rowDefinition in RowDefinitions.Skip(1)) { dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(0, rowDefinition.Offset), new Point(ActualWidth, rowDefinition.Offset)); } foreach (var columnDefinition in ColumnDefinitions.Skip(1)) { 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)); } else if (GridLinesVisibility == GridLinesVisibilityEnum.Vertical) { 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)); } else if (GridLinesVisibility == GridLinesVisibilityEnum.Horizontal) { foreach (var rowDefinition in RowDefinitions) { dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(0, rowDefinition.Offset), new Point(ActualWidth, rowDefinition.Offset)); } dc.DrawRectangle(Brushes.Transparent, new Pen(GridLineBrush, GridLineThickness), new Rect(0, 0, ActualWidth, ActualHeight)); } } base.OnRender(dc); }