title: Creating a grid from string using XamlReader
body: <p>I have a string representation of a XAML Grid like this:</p>
  
  <pre><code>&lt;Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
      &lt;Canvas Background="Yellow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
          &lt;Label Content="textik" /&gt;
      &lt;/Canvas&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>What I need to do is create a Grid object out of this string. I tried a lot of approaches, but so far the closest is the code below:</p>
  
  <pre><code>string content = "&lt;Grid xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"&gt;&lt;Canvas Background=\"Yellow\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"&gt;&lt;Label Content=\"textik\" /&gt;&lt;/Canvas&gt;&lt;/Grid&gt;";
  
  // the string is created programatically, I just put it here to see what it looks like at the end of the process
  
  Stream stream = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(content));
  
  object objGrid = XamlReader.Load(stream);
  Grid myGrid = (Grid) objGrid;
  </code></pre>
  
  <p>However, the XamlParsedException occurs saying that the root element is missing.</p>
  
  <p>Do I have a mistake in a XAML code that I just cannot see? Or is the approach bad?</p>
  
  <p>Thanks for an answer</p>