簡體   English   中英

XamlReader官方代碼片段為我拋出異常

[英]XamlReader official code snippet throwing exception for me

我正在構建一個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應該支持加載方法。 有任何想法嗎?

看起來他們的XAML中有一個拼寫錯誤 - 他們在命名空間URI之前缺少xmlns=

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

(換行包裝以便於閱讀。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM