从字符串转换为数据在Silverlight? [英] Convert from string to data in silverlight?
本文介绍了从字符串转换为数据在Silverlight?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我试图做到这一点:
Basically I'm trying to do this:
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类...
but it won't compile, silverlight does not appear to have a TypeDescriptor class...
推荐答案
试试这个: -
Path path = XamlReader.Load("<Path Data=\"M 250,40 L200,20 L200,60\" />") as Path;
修改
本来应该是:
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);
请参阅跟进的问题:的 XAML解析异常试图加载代码隐藏从XAML
See follow up question: xaml parse exception when attempting to load xaml from codebehind
这篇关于从字符串转换为数据在Silverlight?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文