WPF Drawing Templates

I struggle with creating different brushes to fill in various shapes or backgrounds. Here are some templates I'm struggling with creating:

  • <<<<→ →
  • <| <| <| <| > | > | > | >
  • ////////
  • \\\\
  • ||||||||

I was able to create \\\, ////// and |||||| with a linear gradient, but the first two were causing me problems. BTW, the second is a triangle.

Any suggestions or help are welcome.

+4
source share
2 answers

You need to use TileBrush . Define a single tile pattern using Drawing or an image and repeat it using DrawingBrush or ImageBrush . The documentation is quite extensive on this subject, examples should give you some ideas.

+5
source

You can create composite gradients with a paint brush. For example, here is a diamond gradient that you can insert into a window for testing:

 <Window.Background> <DrawingBrush> <DrawingBrush.Drawing> <DrawingGroup> <DrawingGroup.Children> <GeometryDrawing> <GeometryDrawing.Geometry> <RectangleGeometry Rect="0,0,100,100"/> </GeometryDrawing.Geometry> <GeometryDrawing.Brush> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing> <GeometryDrawing.Geometry> <RectangleGeometry Rect="100,0,100,100"/> </GeometryDrawing.Geometry> <GeometryDrawing.Brush> <LinearGradientBrush StartPoint="1,0" EndPoint="0,1"> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing> <GeometryDrawing.Geometry> <RectangleGeometry Rect="0,100,100,100"/> </GeometryDrawing.Geometry> <GeometryDrawing.Brush> <LinearGradientBrush StartPoint="0,1" EndPoint="1,0"> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing> <GeometryDrawing.Geometry> <RectangleGeometry Rect="100,100,100,100"/> </GeometryDrawing.Geometry> <GeometryDrawing.Brush> <LinearGradientBrush StartPoint="1,1" EndPoint="0,0"> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> </DrawingGroup.Children> </DrawingGroup> </DrawingBrush.Drawing> </DrawingBrush> </Window.Background> 

ASCII graphs are not expressive enough, but perhaps this is what you meant by <lt; <→>:

alt text

+5
source

Source: https://habr.com/ru/post/1333527/


All Articles