Search code examples
wpfpathgeometrylinesegment

WPF, convert Path.DataProperty to Segment objects


I was wondering if there was a tool to convert a path data like "M 0 0 l 10 10" to it's equivalent line/curve segment code.

Currently I'm using:

string pathXaml = "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Data=\"M 0 0 l 10 10\"/>";
Path path = (Path)System.Windows.Markup.XamlReader.Load(pathXaml);

It appears to me that calling XamlParser is much slower than explicitly creating the line segments. However converting a lot of paths by hand is very tedious.


Solution

  • This program will do the conversion: http://stringtopathgeometry.codeplex.com/