Path.Data Dependency Property Initialization from String - Take 2
Day or to ago, I've blogged how to initialize Path.Data property in Silvelright 2 Beta 2 from string. In this post I've mention, that probably the best and the right way to do it is develop functionality similar to WPF's PathFigureCollectionConverter object.
Now it exists: the porting of PathFigureCollectionConverter functionality for Silverlight 2 Beta 2 in my CodePlex project.
Here is usage sample (just add reference to your project):
XAML
<Path x:Name="path" Canvas.Left="10" Canvas.Top="30" Stroke="Black" Height="200" Width="200"/>
CSharp
PathConverter.StringToPathGeometryConverter conv = new PathConverter.StringToPathGeometryConverter();
PathGeometry pathData = conv.Convert(pathString);
path.SetValue(Path.DataProperty, pathData);
The result (path string was "M 16.749,115.917C 16.749,85.5106 58.2626,70.0341 84.4816,68.9416C 110.701,67.8491 136.028,70.1342 147.844,76.0426C 153.853,79.0469 154.945,80.9587 154.945,84.2361C 154.945,86.5613 155.331,122.651 155.331,141.146C 155.331,148.698 152.989,150.416 150.029,151.514C 138.741,155.701 16.749,201.04 16.749,115.917 Z"):
All binaries, sources and samples at CodePlex.
If you like it - vote for this in CodePlex.
Next step is to implement IValueConverter to allow usage of this library for binding... Stay tuned!
Update: IValueConverter & Convert-Back-To-String implemented. Get updated code/binaries/samples here.
Update 2: Support for FillRules syntax added. Updated code/binaries here.
Enjoy,
Alex