Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange issue when using XamlReader to load xaml with xml:space="preserve"
    text
    copied!<p>I found a very strange issue when to use XamlReader to load the menu of my app from a predefined xaml file. I need to define the attribute of <code>xml:space="preserve"</code> and the xaml is like this: </p> <pre><code>&lt;m:MenuManager&gt; ... &lt;m:Resource&gt; &lt;m:Resource.ResourceTitle&gt; &lt;sys:String xml:space="preserve"&gt;Click the Button&amp;#xA;(InvokeCommandAction)&amp;#xA;View&lt;/sys:String&gt; &lt;/m:Resource.ResourceTitle&gt; &lt;/m:Resource&gt; ... &lt;/m:MenuManager&gt; </code></pre> <p>Load the xaml content to the string and use <code>XamlReader.Load</code> to convert it to the MenuManager object. When at the first time the <code>XamlReader.Load</code> method is called, it will only return the words within the tag <code>&lt;sys:String xml:space="preserve"&gt;</code> , and the expected result only returned at the second time. </p> <pre><code> var uri = new Uri("/Sample;component/Assets/Menu.xaml", UriKind.Relative); var info = Application.GetResourceStream(uri); string xaml = null; using (StreamReader reader = new StreamReader(info.Stream)) { xaml = reader.ReadToEnd(); } //when the first time load, only a string value of //"Click the Button&amp;#xA;(InvokeCommandAction)&amp;#xA;View" is returned var temp1 = XamlReader.Load(xaml); //when the second time load, all menu content loaded successfully and //converted to the object of MenuManager readXaml = XamlReader.Load(xaml) as MenuManager; </code></pre> <p>When I remove the attribute <code>xml:space="preserve"</code> or change it to <code>xml:space="default"</code> it will work fine and I can get the object of MenuManager by calling the method <code>XamlReader.Load</code> only once.But I really need keep the whitespace on my page, and the code here looks so strange. Can anybody please explain this? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload