title: Binding a resource to a custom control property
body: <p>I am creating a custom button that shows slightly faded text normally, and full-strength text on a <code>MouseOver</code> or <code>MouseDown</code>. I have defined two resources in the <code>Generic.xaml</code> of my control to represent the brushes for these text colors:</p>
  
  <pre><code>&lt;!-- Text Brushes --&gt;
  &lt;SolidColorBrush x:Key="NormalTextBrush" Color="Black" /&gt;
  &lt;SolidColorBrush x:Key="FadedTextBrush" Color="Gray" /&gt;
  </code></pre>
  
  <p>The control compiles and works fine in that configuration.</p>
  
  <p>But I want to let the control user set the text color, using the custom control's <code>Foreground</code> property. So, I changed the resource declarations to this:</p>
  
  <pre><code>&lt;!-- Text Brushes --&gt;
  &lt;SolidColorBrush x:Key="NormalTextBrush" Color="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}" /&gt;
  &lt;SolidColorBrush x:Key="FadedTextBrush" Color="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorConverter}, ConverterParameter='1.2'}" /&gt;
  </code></pre>
  
  <p>The second declaration uses an <code>HSL</code> value converter to fade the text color.</p>
  
  <p>Now the control doesn't work, and I get the following error in the output window:</p>
  
  <pre><code>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Foreground; DataItem='TaskButton' (Name='Button1'); target element is 'SolidColorBrush' (HashCode=38118303); target property is 'Color' (type 'Color')
  System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Foreground; DataItem=null; target element is 'SolidColorBrush' (HashCode=47449297); target property is 'Color' (type 'Color')
  </code></pre>
  
  <p>I'm not sure what the <code>Data Error</code> is telling me. Can anyone tell me what's going on and how to fix it? Thanks for your help.</p>