I am creating a custom button that shows slightly faded text normally, and full-strength text on a MouseOver or MouseDown. I have defined two resources in the Generic.xaml of my control to represent the brushes for these text colors:
<!-- Text Brushes -->
<SolidColorBrush x:Key="NormalTextBrush" Color="Black" />
<SolidColorBrush x:Key="FadedTextBrush" Color="Gray" />
The control compiles and works fine in that configuration.
But I want to let the control user set the text color, using the custom control's Foreground property. So, I changed the resource declarations to this:
<!-- Text Brushes -->
<SolidColorBrush x:Key="NormalTextBrush" Color="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
<SolidColorBrush x:Key="FadedTextBrush" Color="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorConverter}, ConverterParameter='1.2'}" />
The second declaration uses an HSL value converter to fade the text color.
Now the control doesn't work, and I get the following error in the output window:
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')
I'm not sure what the Data Error is telling me. Can anyone tell me what's going on and how to fix it? Thanks for your help.