views:

487

answers:

2
A: 

Hi David.

Check out this post: Using Data Binding with Static Resources in WPF

We had the same problem in our software and came up with this solution. Basically you create a class that implements an extension to the static resource class of WPF which handles binding and then consume it on your XAML code. Pretty easy to use.

smoura
A: 

I have selected smoura's answer as being the correct one, because it does answer the question that I had asked. However, I don't want to lead anyone astray who may be researching this question down the road, particularly with respect to the WPF Calendar control.

I decided I was off course in using a resource, and then trying to bind that resource. A much better approach is to simply bind the Color property directly. To do that, I created a simple IValueConverter called BrushToColorConverter, then used that to bind the named brush's color to the Foreground property of the UserControl that I am creating. The markup looks like this:

<!-- Modification: Changed template brush color -->
<SolidColorBrush x:Name="TextColor" Color="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource BrushToColorConverter}}" />

This approach completely eliminates the Color resource that I had used previously. It is simpler and, I suspect, more efficient.

David Veeneman