2013-02-18 34 views
0

我正在構建一個Windows 8應用程序,並且想要解析來自Web服務的一些XAML以放入RichTextBlock中。我試圖使用XamlReader來使用它,但this code from Microsoft's documentation在我的環境中拋出異常。XamlReader官方代碼片段拋出異常

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(微軟的Visual Studio 2012高級版11.0.51106.01,Microsoft .NET Framework版本4.5.50709)。文檔說Windows 8應該支持加載方法。有任何想法嗎?

回答

2

它看起來像有在他們的XAML一個錯字 - 他們缺少的命名空間URI之前xmlns=

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

(線爲了便於閱讀。)

+0

是啊,這做到了。奇怪的是,當我使用我自己的代碼而不是從微軟複製粘貼時,我包含了xmlns =並且仍然ch咽,但至少我從現在開始有了SOMEWHERE。謝謝! – user460847 2013-02-18 19:05:17