Geometry Mini-Language WPF in VB.NET

In this article you will learn the Geometry Mini-Language in WPF.
  • 3240

Geometry Mini-Language: Defining each line, arc, and curve in a complex path is extremely verbose and unnecessary after all, it's likely that complex paths will be generated by a design tool rather than written by hand, so the clarity of the markup isn't all that important. To resolve this problem WPF have a additional syntax for defining geometries that allows you to represent detailed figures with much smaller amounts of markup, this syntax described as the Geometry Mini-Language.

To understand the mini-language, you need to realize that it is essentially a long string holding a series of commands. These commands are read by a type converter that then creates the corresponding geometry. Each command is a single letter and is optionally followed by a few bits of numeric information (such as X and Y coordinates) separated by spaces.

Lets take a example which clear you more that how Geometry Mini-Language work or we can say that how you can use the Geometry Mini-Language in WPF.

A bit earlier you created a basic triangle using a closed path with two line segments, like:

Example of an Triangle

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Path Stroke="Blue">
        <Path.Data>
            <PathGeometry>
                <PathFigure IsClosed="True" StartPoint="50,100">
                    <LineSegment Point="150,10" />
                    <LineSegment Point="150,100" />
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>
</
Window>

Output Window

gmini.gif

Now we do the same again in Geometry Mini-Language, the given below path uses a sequence of four commands. The first comman(M) creates the PathFigure and sets the starting point to (10, 100). The following two commands (L) create line segments. The final command (Z) ends the PathFigure and sets the IsClosed property to true. The commas in this string are optional, as are the spaces between the command and itsparameters, but you must leave at least one space between adjacent parameters and commands. That means you can reduce the syntax even further to this less-readable form:

<PathGeometry Figures="M 50,100 L 150,10 L 150,100 Z" />

Example of Geometry Mini-Language

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Path Stroke="Blue">
        <Path.Data>
            <PathGeometry Figures="M 50,100 L 150,10 L 150,100 Z" />
        </Path.Data>
    </Path>
</
Window>

Output Window

gmini.gif

 

Conclusion

Hope this article help you to understand the Geometry Mini-Language in WPF.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.