It’s easy to draw and manage shapes in Expression Blend, but when it comes to generate shapes automatically we realize that it’s much harder. Lucky for us all properties can be set in code and all shapes can be drawn.
First we have to have canvas to draw on:
When we got that we can write some C# code, and create a path.
But what is this Path.Data property? This is list of points in Path Markup Syntax. You can learn more about this language here: http://msdn.microsoft.com/en-us/library/bb412389.aspx
Here is an example of elipse as a data for path variable.
Another nice thing is that we can add anything we want from code. Let’s add linear gradient brush. First we must define gradient stops and set it’s color and offset – place where color will appear(value must be between 0 and 1). Then we have to create LinearGradientBrush and add stops to its gradientStops collection. Remember to set StartPoint and EndPoint properties of linear gradient brush. This is where gradient will start and end. And don’t forget to set Path.Fill property and assign our brush to it.
And the result should look like this:
And last bu not least it’s drawing lines. After drawing ellipse drawing line should be piece of cake, but at the other hand it’s very useful.
Again we create Geometry object, which is called LineGeometry, set it’s start and end point and assign that object to our Path.Data object.
The result you should see below:







