title: WPF: How to bind to a nested property?
body: <p>I can bind to a property, but not a property within another property. Why not? e.g.</p>
  <pre><code>&lt;Window DataContext=&quot;{Binding RelativeSource={RelativeSource Self}}&quot;...&gt;
  ...
      &lt;!--Doesn't work--&gt;
      &lt;TextBox Text=&quot;{Binding Path=ParentProperty.ChildProperty,Mode=TwoWay}&quot; 
               Width=&quot;30&quot;/&gt;
  </code></pre>
  <p>(Note: I'm not trying to do master-details or anything. Both properties are standard CLR properties.)</p>
  <p><strong>Update:</strong> the problem was that my ParentProperty depended on an object in XAML being initialized. Unfortunately that object was defined later in the XAML file than the Binding, so the object was null at the time when my ParentProperty was read by the Binding. Since rearranging the XAML file would screw up the layout, the only solution I could think of was to define the Binding in code-behind:</p>
  <pre><code>&lt;TextBox x:Name=&quot;txt&quot; Width=&quot;30&quot;/&gt;
  
  // after calling InitializeComponent()
  txt.SetBinding(TextBox.TextProperty, &quot;ParentProperty.ChildProperty&quot;);
  </code></pre>