title: Access Element inside Silverlight DataTemplate
body: <p>I have not been able to find a clean solution to the following problem even though there are a few related questions already on SO.</p>
  
  <p>If I have a data template that is being used multiple times, for example, a TreeViewItem.HeaderTemplate, how can I change something the template for only some of the TreeViewItems.</p>
  
  <p>For example, let's say my TVI HeaderTemplate has a textblock and depending on the string, I want to make the fontweight bold.</p>
  
  <p>I want to do something like this: </p>
  
  <pre><code>((TextBlock)myTreeView.Items.ElementAt(0).FindName("myTextBlock")).FontWeight = FontWeights.Bold;
  </code></pre>
  
  <p>Does anyone have a solution for this? --> Thanks Evan</p>
  
  <p><strong>Edit:</strong> Is there a way to write a generic function to get a control based on it's name even if it's in a data template?</p>
  
  <p><code>LayoutRoot.FindName("myTextBlock");</code> would work if myTextBlock was not in a datatemplate. How can I write a <code>findElementInDataTemplate(string elementName, string parentName)</code> function? </p>
  
  <p>The reason Evan's answer is not what I'm looking for is because I am developing a control. I want the application developer who uses my control to be able to change any element in the control. If I use Evan's solution, that would require the application developer to have access to all the templates in the control. Possible, but not ideal. Thanks!</p>