title: WPF Bind ControlTemplate's content to Property in Control?
body: <p>I want to bind Border.Background in my Button ControlTemplate to the Background Property of my  button. Usually I would use a TemplateBinding:</p>
  
  <pre><code>  &lt;Style TargetType="Button" x:Key="ColuredButton"&gt;
                  &lt;Setter Property="Background" Value="LightGreen"/&gt;
                  &lt;Setter Property="Template"&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType="Button"&gt;
                              &lt;Border x:Name="Border" CornerRadius="2" BorderThickness="1" BorderBrush="Gray"&gt;
                                 &lt;Border.Background&gt;
                                      &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,1"&gt;
                                          &lt;GradientStop Color="{TemplateBinding Foreground}"/&gt;
                                          &lt;GradientStop Color="{TemplateBinding Background}"/&gt;
                                      &lt;/LinearGradientBrush&gt;
                                  &lt;/Border.Background&gt;
                                      &lt;ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" /&gt;
                              &lt;/Border&gt; 
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Style&gt;
  </code></pre>
  
  <p>But I get the error: "Cannot set TemplateBinding if not in a Template".. But I am in a Template! (It works if I dont use LinearGradientBrush and bind the borders Backround Property directly to {TemplateBinding Background}....</p>