title: Datacontext of ControlTemplates
body: <p>How does a ControlTemplate handle the datacontext?</p>
  
  <p>Using the the follow Template</p>
  
  <pre><code>&lt;ControlTemplate x:Key="ToolbarButtonHover" TargetType="Button"&gt;
      &lt;Grid Name="backgroundGrid"&gt;
          &lt;Image Source="{DynamicResource ResourceKey=Img}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"&gt;&lt;/Image&gt;
      &lt;/Grid&gt;
      &lt;ControlTemplate.Triggers&gt;
          &lt;DataTrigger Binding="{Binding Path=DataContext.ToolSelected, RelativeSource={RelativeSource TemplatedParent}}" Value="Unlink"&gt;
              &lt;Setter TargetName="backgroundGrid" Property="Background" Value="Red" /&gt;
          &lt;/DataTrigger&gt;
      &lt;/ControlTemplate.Triggers&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>with the control</p>
  
  <pre><code>&lt;Button Content="Button" 
          Template="{StaticResource ResourceKey=ToolbarButtonHover}" 
          Height="24" Width="24" Background="Red"&gt;
      &lt;Button.Resources&gt;
          &lt;ImageSource x:Key="Img"&gt;Resources/Icons/toolSelect.png&lt;/ImageSource&gt;
      &lt;/Button.Resources&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>But this does not make the background red. I have verifyed that the value of the ToolbarViewModel Property <code>ToolSelected</code> is in fact Unlink by having a <code>&lt;Label Content="{Binding ToolSelected}"/&gt;</code> next to the controll.  So i believe the problem is that the template does not use the correct <code>DataContext</code>, but I'm not sure of this. That's why i ask you for help.</p>
  
  <p>The Control lies in a custom usercontrol, and the ToolbarViewModel is set as context for all of it, like so. </p>
  
  <pre><code>&lt;UserControl.DataContext&gt;
      &lt;local:ToolboxView/&gt;
  &lt;/UserControl.DataContext&gt;
  </code></pre>