probably a trivial question: i need to fill a rectangle with a checker board pattern where each cell is 1×1 pixel in size. how to create a vector geometry for this pattern in XAML? i am not using Blend I am doing my vector graphics by hand.
thanks
konstantin
You’d get the following from the XAML below:
Here’s the long version of the XAML, spelling out what geometry is being created. The Rect attribute of the RectangleGeometry element takes a left,top,width,height sequence.
The following shorter version renders the exact same image, but uses a shorthand notation for the geometry. The checkerboard tiles are rendered as a path.
Caveat: this works well when the rectangle is positioned on integer coordinates. Should it be positioned on a fractional coordinates (e.g. Canvas.Left=”10.5″ instead of “10”), the brush will be anti aliased and will lose the sharp pattern. SnapToDevicePixels will not help. As long as the rectangle’s position is known, you could set the DrawingBrush‘s RelativeTransform to offset the fractional component, in order to avoid anti-aliasing.