0

我正在构建一个 Windows 8 应用程序,并希望从 Web 服务中解析一些 XAML 以放入 RichTextBlock。我正在尝试使用 XamlReader 来使用它,但是Microsoft 文档中的这段代码在我的环境中引发了异常。

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 版本 11.0.51106.01,Microsoft .NET Framework 版本 4.5.50709)。文档说 Windows 8 应该支持加载方法。有任何想法吗?

4

1 回答 1

2

看起来他们的 XAML 中有一个错字 - 他们在xmlns=命名空间 URI 之前缺少一个:

string xaml = "<Ellipse"
   + " Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill=\"Red\""
   + " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";

(为了便于阅读,换行。)

于 2013-02-18T18:40:47.037 回答