0

I just started using Geomectry Drawing in xaml and I came across this interesting article https://msdn.microsoft.com/en-us/library/aa480159.aspx. Here, I find out that the following drawingbrush gives a graph diagram as an output.

<DrawingBrush x:Name="gridBackgroundBrush" 
    Viewport="0,0,10,10" 
    ViewportUnits="Absolute"
    TileMode="Tile">
  <DrawingBrush.Drawing>
    <DrawingGroup>
      <DrawingGroup.Children>
        <GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="Green" />
        <GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Green" />
      </DrawingGroup.Children>
    </DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>

From further reading, I figure out that M means starting point or move to, L means line and Z means close but could not figure out how this will give me two lines - one horizontal and one vertical? Any help understanding this will be highly appreciated. Thanks.

Chris W.
  • 22,835
  • 3
  • 60
  • 94
Sonny
  • 64
  • 5
  • Well, there are *2* `GeometryDrawing`s there, one for the horizontal line and one for the vertical line... – Pieter Witvoet Mar 29 '16 at 22:05
  • Thats right. I just don't understand what L1,0 1,0.1, 0, means like what is 1,0? Is that the starting point? – Sonny Mar 29 '16 at 22:56

2 Answers2

3

So here's a quick break down for you.

Your example is a DrawingBrush which is explicitly set to TileMode="Tile" which is the equivalent of repeat-x/repeat-y if you're more familiar with CSS as example. So it's instructed to repeat itself up-down/left-right repeating.

Your two bits of your Geometry Drawing if translated individually are two squares with one stretching vertical, one stretching horizontal. While your explicitly set ViewportUnits is dictating the size and position effectively making repeated columns and rows.

Your Path Geometry uses Path Markup Syntax to draw these lines as you pointed out. For a more visual explanation replace your Brush on each.

 <GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="Red" />
 <GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Blue" />

...and voila! You have yourself a repeated line background with effective vertical/horizontal columns creating your grid. See links for more detail and hope this helps. Cheers!

Oh, and the question you got that from also had a link that would have shed a little light on it but not as much as you'd like so I didn't mark this duplicate.

ADDENDUM:

A little more clarification. Though if you want to learn more I'd follow the documentation link someone spent a lot of time writing to answer this already. Think if you have an x,y grid you're drawing points on.

Say you're using the pen tool in something like Adobe Illustrator, or Blend. Your first click is setting your M as your start point based on the relative size of the container. Then you click in another spot...well now you effectively have a L line.

So when we see: M0,0 L1,0 that's our first starting Line. In this case it's the top corner stretching to the right corner since there's not another anchor in the line between the two points. The next set acts as the anchor to tell that line to change it's direction to make the side, and so on, and so fourth until you hit the end at Z. Hope this helps but I would encourage the documentation first.

Here they are individually if you feel like tinkering with numbers and learning:

<Path Data="M0,0 L1,0 1,0.1, 0,0.1Z" 
      Height="150" Width="150" Stroke="Red" />
<Path Data="M0,0 L0,1 0.1,1, 0.1,0Z" 
      Height="150" Width="150" Stroke="Blue" />
Community
  • 1
  • 1
Chris W.
  • 22,835
  • 3
  • 60
  • 94
  • Thanks a lot. Your explanation is very helpful. Could you also please explain what the numbers after the L indicates? – Sonny Mar 30 '16 at 00:08
  • Check updated answer, I'll have to swing back if you don't find a full tutorial before then. Busy days. Cheers! – Chris W. Mar 30 '16 at 02:53
  • I'm pretty sure I've seen some pretty awesomely detailed explanations from @Clemens but I can't seem to find them. – Chris W. Mar 30 '16 at 03:22
  • Thanks @Chris. That's a neat answer. I appreciate your time and effort. Please update your answer with a link if you find one. – Sonny Mar 30 '16 at 13:18
  • @Sonny A quick google search will yield a lot. Maybe start with a video like this [one](https://www.youtube.com/watch?v=xetwJDlfFNc) if you want to get a crash course. I just skimmed through it but he covers some ArcSegment as well as the `M0,0 L0,1` Line segment stuff you're showing. Best of luck! – Chris W. Mar 30 '16 at 13:34
1

I came cross the same thing when I used GMaps V3. It is an SVG path notation path that allows you to draw on WPF and on browsers too. You can find the complete documentation in the link.

Bassem
  • 820
  • 9
  • 17