Search code examples
c#wpfstylesvisualbrushdrawingbrush

Multi Coloured Geometry Control Background


enter image description here

I'm trying to create some kind of brush that achieves the affect shown in the picture. It is intended for a control's Background.

I can achieve the affect using VisualBrush with the above image as the source but I'm applying it to ~100 controls and there's some latency I don't experience with linear and solid brushes.

I attempted to use GeometryDrawing (in DrawingBrush and VisualBrush) but it doesn't seem to allow for multiple colors. LinearGradientBrush doesn't seem fit for this purpose as I can't 'change direction' or layer gradients.

Is there any way to achieve this affect? Am I going to have to use the laggy pictures? ;-;


Solution

  • This should do the job:

    <DrawingBrush Stretch="Uniform">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Geometry="M0,0 L8,0 8,8 0,8Z" Brush="Black"/>
                <GeometryDrawing Geometry="M0,0 L2,0 0,2Z" Brush="LightBlue"/>
                <GeometryDrawing Geometry="M6,8 L7,7 8,8Z" Brush="Red"/>
                <GeometryDrawing Geometry="M8,6 L7,7 8,8Z" Brush="DarkGreen"/>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>