WPF - Binding a color resource to the data object within a DataTemplate

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-22T09:40:23Z Indexed on 2010/05/22 11:10 UTC
Read the original article Hit count: 454

Filed under:
|
|
|
|

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>

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET