Convert from string to data in silverlight?

北慕城南 提交于 2019-12-01 22:20:29
AnthonyWJones

Try this:-

  Path path = XamlReader.Load("<Path Data=\"M 250,40 L200,20 L200,60\" />") as Path;

Edit

Should have been:

  public static GeneratePath(string data)
  {
      string pathEnvelope = "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Data=\"{0}\"/>")
      return XamlReader.Load(String.Format(pathEnvelope, data)) as Path;
  }

Usage:-

  string data = "M 250,40 L200,20 L200,60";

  Path path = GeneratePath(data);

See follow up question: xaml parse exception when attempting to load xaml from codebehind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!