我正在构建一个Windows8应用程序,并希望从web服务中解析一些XAML以放入RichTextBlock中。我正在尝试使用XamlReader来使用它,但是this code from Microsoft's documentation在我的环境中抛出了一个异常。
string xaml = "<Ellipse Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill=\"Red\" \"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";
object ellipse = Windows.UI.Xaml.Markup.XamlReader.Load(xaml);在执行第二行时,我得到了一个异常:
An unhandled exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in mscorlib.dll
WinRT information: illegal qualified name character [Line: 1 Position: 68]
Additional information: Unspecified error我的VS版本是Microsoft Visual C# 2012 (Microsoft Visual Studio Premium 2012 Version 11.0.51106.01,Microsoft .NET Framework4.5.50709)。文档说Windows8应该支持load方法。有什么想法吗?
发布于 2013-02-19 02:40:47
看起来他们的XAML中有一个拼写错误-他们在命名空间URI之前缺少一个xmlns=:
string xaml = "<Ellipse"
+ " Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill=\"Red\""
+ " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";(换行以提高可读性。)
https://stackoverflow.com/questions/14943089
复制相似问题