Elad8a
Topic Author
Posts: 11
Joined: 17 Jun 2018, 20:52

DrawingBrush alternative to draw a 2D grid as a canvas background

08 Apr 2022, 12:31

I have the following xaml the is used to fill a canvas with a 2D grid background:
<UserControl x:Class="EM.Map2DDisplay"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:EM"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Canvas>
        <Canvas.Background>
            <DrawingBrush TileMode="Tile" Viewport="0,0,50,50" ViewportUnits="Absolute">
                <DrawingBrush.Drawing>
                    <GeometryDrawing>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0,50,50"/>
                        </GeometryDrawing.Geometry>
                        <GeometryDrawing.Pen>
                            <Pen Brush="Gray" Thickness="1"/>
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>
                </DrawingBrush.Drawing>
            </DrawingBrush>
        </Canvas.Background>    
    </Canvas>
</UserControl>

Unfortunately, using the solution provided in a similar question will not work as the pattern is 2 dimensional rather than 1 dimensional.

viewtopic.php?p=13789&hilit=DrawingBrush#p13789

How can this be achieved with Noesis? Is there a plan to support DrawingBrush?

Update:

Ok, I think my current direction is to inherit from Noesis::Canvas and override its OnRender Method to draw the grid background using DrawingContext::DrawRectangle or DrawingContext::DrawLine

Now the question is - Is this a good approach? specifically. An Ideal approach would achieve instanced rendering of triangles / lines. can this be achieved?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: DrawingBrush alternative to draw a 2D grid as a canvas background

11 Apr 2022, 13:01

We have plans to implement Drawings for our next major version (NoesisGUI 3.2): #1547

In the meantime the easiest way to achieve what you want is to tile a texture with ImageBrush. If you need it to be scalable and keep pixel perfect, then using OnRender to draw the lines is a good approach as you will be using the low level drawing primitives instead of heavy objects like Shapes.

Who is online

Users browsing this forum: Bing [Bot] and 8 guests