title: Silverlight - Get the ItemsControl of a DataTemplate
body: <p>I have a Silverlight application that is using a DataGrid. Inside of that DataGrid I have a DataTemplate that is defined like the following:</p>
  
  <pre><code>&lt;Grid x:Name="myGrid" Tag="{Binding}" Loaded="myGrid_Loaded"&gt;
    &lt;ItemsControl ItemsSource="{Binding MyItems}" Tag="{Binding}"&gt;
      &lt;ItemsControl.ItemTemplate&gt;
        &lt;DataTemplate&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
            &lt;StackPanel Orientation="Horizontal" Width="138"&gt;
              &lt;TextBlock Text="{Binding Type}" /&gt;
              &lt;TextBox x:Name="myTextBox" TextChanged="myTextBox_TextChanged" /&gt;
            &lt;/StackPanel&gt;
          &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
    &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>When a user enters text into the TextBox, I have an event (myTextBox_TextChanged) that must be fired at this point. When that event gets fired, I would like to get the ItemsControl element that is the container for this TextBox. How do I get that ItemsControl from my event handler?</p>
  
  <p>Please note: Because the ItemsControl is in the DataTemplate of DataGrid, I don't believe I can just add an x:Name and reference it from my code-behind. Or is there a way to do that?</p>
  
  <p>Thank you!</p>