Page 1 of 1

Hint: how to programmatically set a Path.Data

Posted: Sun Jul 10, 2016 5:29 am
by xidea
Hello,

recently, I've encountered some problem in drawing paths by code. You need to set the Data property of a Path object, but you cannot write the XAML code, as XamlReader is not implemented, and neither Geometry.Parse. Also, you cannot use (at the moment) the shape management functions of the framework, because of some bug in the C#XML4HTML5 (beta) libraries. The Data property doesn't accept a string, it accepts Geometry types.

A working way is to construct a string using the Path definition mini language, and pass to the path object in this way:

Code: Select all

var p = new Path();
var pathData = "M10,10 L10,120 120,120 200,100, 200,150"
p.Data = (Geometry)DotNetForHtml5.Core.TypeFromStringConverters.ConvertFromInvariantString(typeof(Geometry), pathData);
cnvMyCanvas.Children.Add(p);


This code creates a path and adds it to a Canvas object.



Flavio