Pergunta

I'm building a Windows 8 app, and want to parse some XAML from a web service to put in a RichTextBlock. I'm trying to use XamlReader to use this, but this code from Microsoft's documentation is throwing an exception in my environment.

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);

When executing the second line, I get the exception:

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

My version of VS is Microsoft Visual C# 2012 (Microsoft Visual Studio Premium 2012 Version 11.0.51106.01, Microsoft .NET Framework Version 4.5.50709). The documentation says Windows 8 should support the load method. Any ideas?

Foi útil?

Solução

It looks like there's a typo in their XAML - they're missing an xmlns= before the namespace URI:

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

(Line wrapped for readability.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top