title: Datacontext lost with dynamic xaml in WPF
body: <p>I have a window with a simple frame element within it (we'll call it "myFrame"). Within the Window.Loaded I am parsing a string variable (loaded from an external source) with XamlReader.Parse(string) and the result is a Page object (local var is called "myPage"). I'm setting myFrame.Content = myPage.</p>
  
  <p>Inside of the page is a label, like so:  </p>
  
  <pre><code>&lt;label Name="DataBindingTestLabel" Content="{Binding Path=TestLabel, TargetNullValue='Null value'}" /&gt;
  </code></pre>
  
  <p>I am trying to provide an anonymous type (for easy testing) as the frame's datacontext, like:</p>
  
  <pre><code>this.ContentFrame.DataContext = new { TestLabel = "Hello, world." };
  </code></pre>
  
  <p>I have verified that the DataContext property has the value after it's set and keeps the value for as long as I can step through the window's execution, but the value is lost sometime before the window is rendered and the fallback value, "Null value," is displayed.</p>
  
  <p>After enabling databinding tracing, the output window in visual studio shows:  </p>
  
  <blockquote>
    <p>System.Windows.Data Information: 41 : BindingExpression path error: 'TestLabel' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=TestLabel; DataItem=null; target element is 'Label' (Name='DataBindingTestLabel'); target property is 'Content' (type 'Object')</p>
  </blockquote>
  
  <p>Any insight into something I'm doing wrong is most appreciated.</p>