title: WPF Binding inner control with parent data context
body: <p>I made a user control</p>
  
  <pre><code>&lt;UserControl x:Class="MyApp.MyControl"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           mc:Ignorable="d"  x:Name="uc"&gt;
  &lt;Grid Width="Auto" Height="Auto"&gt;
      &lt;TextBlock Text="{Binding Path=DataContext.TextContent, ElementName=uc}"/&gt;
      &lt;TextBlock Text="{Binding Path=DataContext.TextContent2, ElementName=uc}"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want the sub-controls in the defined control(uc) will bind to the properties of uc.DataContext. I used the defined control as follows:</p>
  
  <pre><code>&lt;Window x:Class="Tms.TMSClient.Views.MainWindow" Name="window"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:control="clr-namespace:MyApp"
      xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"&gt;      
  
      &lt;control:MyControl DataContext="{Binding Path=MyControlVM}"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>The DataContext which is assigned to the window has this structure: WindowVM.MyControlVM.TextContent.</p>
  
  <p>The given code does not work because the textbox's DataContext is bound to WindowVM instead. I think the problem may be because the inner textbox is bound before the defined control (uc) is, thus the bounded DataContext for <em>uc</em> does not take effect yet.</p>
  
  <p>What I want is: the custom control (MyControl) will be bound to its corresponding viewmodel (MyControlVM), and the inner elements of MyControl will be bound to the properties of MyControlVM.</p>
  
  <p>Do you have any solutions for this problem?</p>