在Silverlight中从字符串转换为数据?

基本上我正在尝试这样做:

Path path = new Path( ); string sData = "M 250,40 L200,20 L200,60 Z"; var converter = TypeDescriptor.GetConverter( typeof( Geometry ) ); path.Data = ( Geometry )converter.ConvertFrom( sData ); 

但它不会编译,Silverlight似乎没有TypeDescriptor类…

试试这个:-

  Path path = XamlReader.Load("") as Path; 

编辑

本来应该:

  public static GeneratePath(string data) { string pathEnvelope = "") return XamlReader.Load(String.Format(pathEnvelope, data)) as Path; } 

用法:-

  string data = "M 250,40 L200,20 L200,60"; Path path = GeneratePath(data); 

请参阅后续问题: 尝试从代码隐藏加载xaml时xaml解析exception