Posted by: Zeeshan Amjad | June 2, 2010

Using Path in WPF


In WPF Path class is to use to draw the any arbitrary images. This class is directly inherited by Shape class.

Here is a class diagram of classes Path class.

Path

WPF already define few classes for shape, but if you need more flexibility then Path is exactly for this purpose. Here is a class diagram of classes inherited by Shape class.

Shape

Important thing about Path class is introduction of Data variable. Data is a Geometry type variable.

Path_02

Here is a class diagram of Geometry class.

Geometry

Now lets take a look at simple example. In this simple example we are going to make a star shape with the help of path. Here is a complete XAML code of the program.

<Window x:Class="WpfPath.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Path" Height="300" Width="300">
    <Canvas>
        <Path Stroke="Blue" Fill="Yellow"
            StrokeThickness="2" 
            Data="M 50,50 l 15,0 l 5,-15 l 
              5,15 l 15,0 l -10,10 l 4,15 l 
              -15,-9 l -15,9 l 7,-15 Z" />
    </Canvas>
</Window>

Here is the output of this program.

PathOutput

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: