Hint: how to programmatically set a Path.Data

xidea
Posts: 33
Joined: Thu Jun 30, 2016 7:04 pm

Hint: how to programmatically set a Path.Data

Postby xidea » Sun Jul 10, 2016 5:29 am

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

Return to “General Discussion and Other”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

 

 

cron