DrawingBrush to WPF DataGrid cells as Background

180 views Asked by At

I'd like to set a DrawingBrush to DataGridCelland I use

<DrawingBrush TileMode="Tile" ViewportUnits="RelativeToBoundingBox" Viewport="0,0,0.05,1">
     <DrawingBrush.Drawing>
         <DrawingGroup>
              <GeometryDrawing>
                   <GeometryDrawing.Pen>
                         <Pen Brush="Gray" Thickness="0.05"/>
                    </GeometryDrawing.Pen>
                    <GeometryDrawing.Geometry>
                          <LineGeometry StartPoint="0,1" EndPoint="1,0" />
                    </GeometryDrawing.Geometry>
              </GeometryDrawing>
          </DrawingGroup>
     </DrawingBrush.Drawing>
</DrawingBrush>

I have undesired result when DataGridCells have unequal widths like below.

enter image description here

How should I change the Brush so that regardles of the widht of the individual cells the result would look like this.

enter image description here

1

There are 1 answers

0
dkozl On

Change ViewportUnits from RelativeToBoundingBox to Absolute and adjust Viewport.

The coordinate system is not relative to a bounding box. Values are interpreted directly in local space.

Something like this:

<DrawingBrush 
    x:Key="DrawingBrush" 
    TileMode="Tile" 
    ViewportUnits="Absolute" 
    Viewport="0,0,5,15">

which looks like this

result