title: wpf binding when using datatemplate
body: <p>ok currently i have this piece of code:</p>
  
  <pre><code>&lt;TabItem Style="{DynamicResource MyStyle" x:Name="TabCustomers" Padding="0,1,4,1"
   Header={Binding Path=customersHeader}/&gt;
  </code></pre>
  
  <p>Now i want to add an icon there so I do (by removing the header above):</p>
  
  <pre><code>&lt;TabItem.Header&gt;
  &lt;StackPanel Orientation="Horizontal"&gt;
       &lt;Image Stretch="UniformToFill" Source="{StaticResource customers}"/&gt;
       &lt;TextBlock x:Key="textblock" Margin="4,0,0,0" 
       Text="{Binding Path=customersHeader}"/&gt;
  &lt;/StackPanel&gt;
  &lt;/TabItem.Header&gt;
  </code></pre>
  
  <p>So far it's ok.
  I would like to generalize this using a datatemplate. I assume i have to do this in my resource dictionary:</p>
  
  <pre><code>&lt;DataTemplate x:Key="TabItemCustomersTemplate" DataType="{x:Type TabItem}"&gt;
  &lt;StackPanel Orientation="Horizontal"&gt;
       &lt;Image Stretch="UniformToFill" Source="{StaticResource customers}"/&gt;
       &lt;TextBlock x:Key="textblock" Margin="4,0,0,0" 
       Text="{Binding Path=customersHeader}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>and change this in my tabitem declaration:</p>
  
  <pre><code>&lt;TabItem ... HeaderTemplate="{StaticResource TabItemCustomersTemplate}".../&gt;
  </code></pre>
  
  <p>So i run into the following issues and questions:
  1) binding doesnt work, why?
  2) how can i access textblock from c#?
  3) how can i generalize this so i dont have to copy this over and over again for different tab items (or other controls for the matter) so that i can pass my own text and image source each time? For example you might use this to create an image button and if you have 20 buttons the code becomes messy.</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you.</p>