WPF - Binding a color resource to the data object within a DataTemplate
- by John
I have a DataTemplate and a SolidColorBrush in the DataTemplate.Resources section.
I want to bind the color to a property of the same data object that the DataTemplate itself is bound to.
However, this does not work. The brush is ignored. Why?
<DataTemplate DataType="{x:Type data:MyData}" x:Name="dtData">
<DataTemplate.Resources>
<SolidColorBrush x:Key="bg" Color="{Binding Path=Color, Converter={StaticResource colorConverter}" />
</DataTemplate.Resources>
<Border CornerRadius="15"
Background="{StaticResource bg}"
Margin="0"
Opacity="0.5"
Focusable="True">
</DataTemplate>