Posted by: rcosic | 11/08/2009

WPF : Geometry mini-language

It is really cool feature of WPF. Instead of typing lots of tags to describe visual elements in your GUI, you can just fill out the property Data of path element with special textual value. I like the way it is designed, because it gives somewhat old-school crypted form. The benefit is that it is short and very straightforward. Take a look!

Consider the following XAML code:

<Path Stroke=”Black”>
    <Path.Data>
        <PathGeometry>
            <PathFigure IsClosed=”true” StartPoint=”10,100″>
                <LineSegment Point=”100,100″ />
                <LineSegment Point=”100,50″ />
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Data>

And now, take a look on condensed “mini language” form:

<Path Stroke=”Blue” Data=”M 10 100 L 100 100 L 100 50 Z” />

Pretty cool, ha?

These are the commands for the Geometry Mini-Language:

F value – Sets the Geometry.FillRule property. Use 0 for EvenOdd, or 1 for NonZero. This command must appear at the beginning of the string (if you decide to use it).
M x,y Creates a new PathFigure for the geometry and sets its start point. This command must be used before any other commands except F. However, you can also use it during your drawing sequence to move the origin of your coordinate system. (The M stands for move).
L x,y – Creates a LineSegment to the specified point.
H x – Creates a horizontal LineSegment using the specified X value and keeping the Y value constant.
V y – Creates a vertical LineSegment using the specified Y value and keeping the X value constant.
A radiusx, radiusY, degrees isLargeArch, isClockwise x,y  – Creates an ArcSegment to the indicated point. You specify the radii of the ellipse that describes the arc, the number of degrees the arc is rotated, and Boolean flags that set the IsLargeArc and SweepDirection properties.
C x1,y1 x2,y2 x,y – Creates a BezierSegment to the indicated point, using control points at (x1, y1) and (x2, y2).
Q x1,y1 x,y – Creates a QuadraticBezierSegment to the indicated point, with one control point at (x1, y1).
S x2,y2 x,y – Creates a smooth BezierSegment by using the second control point from the previous BezierSegment as the first control point in the new BezierSegment.
Z – Ends the current PathFigure and sets IsClosed to true. You don’t need to use this command if you don’t want to set IsClosed to true – instead, simply use M if you want to start a new PathFigure or end the string.

* The text was taken from the book: “Pro WPF in C# 2008″ by Mathew McDonald. Really must have book!


Responses

  1. […] A small summary of this usefull language: WPF : Geometry mini-language | Lamentations of one programmer. […]

  2. I every time spent my half an hour to read this blog’s articles or reviews every day along with a mug of coffee.

  3. This piece of writing gives clear idea for the new people of blogging, that
    genuinely how to do blogging.

  4. Reblogged this on Aventuras en .NET and commented:
    Interesting!


Leave a comment

Categories