Setting Path.Data in code-behind
Solution 1:
I had this probelm too a while ago in winrt. It seems that you cannot asign a "path" value directly in code behind.
However there is a solution here
I used this class in winrt without any problem. All I had to do is change the signatures of the Convert and ConvertBack methods to implement the IValueConverter interface as it is in winrt and not in silverlight. Here they are
public object Convert(object value, Type targetType, object parameter, string language)
{
string path = value as string;
if (null != path)
return Convert(path);
else
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
PathGeometry geometry = value as PathGeometry;
if (null != geometry)
return ConvertBack(geometry);
else
return default(string);
}
Usage: (More or less)
var stringToPathGeometryConverter = new StringToPathGeometryConverter();
string pathData = "m 150,0 A 150,0 0 0 0 150,0 A 150,150 0 0 0 150,0" ;
progressPath.Data = stringToPathGeometryConverter.Convert(pathData);
Solution 2:
Another way to do it is to use XamlReader for this with apropriate string loaded. In C#6.0 it can look like this:
Path pathFromCode = XamlReader.Load($"<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><Path.Data>{stringPathData}</Path.Data></Path>") as Path;