1
votes

I have a DataTrigger that animates Background.Color on a Grid Row. It works good when Background is of type SolidColorBrush because that has a Color property.

But when that Grid Row is highlighted, the Background becomes LinearGradientBrush which does not have a Color property and my storyboard fails with an exception. How do I deal with that ?

Here is my Trigger

    <DataTrigger Binding="{Binding Row.State}" Value="Finished">
        <DataTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard >
                    <ColorAnimation
                                    Storyboard.TargetProperty="Background.(Color)" 
                                    To="LightGreen" Duration="0:0:1" />
                </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
    </DataTrigger>

Here is the exception that I get when row is highlighted.

Additional information: Cannot resolve all property references in the property path 'Background.(Color)'. Verify that applicable objects support the properties.

1

1 Answers

0
votes

I got it fixed.

I used the Storyboard.TargetProperty like this

Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"

Apparently it looks for type by the name SolidColorBrush.

More information about Parenthesis is found at MSDN

In the multiple objects and subproperties form, you must use an owning object to disambiguate the initial property and place parentheses around this initial object.property combination. Thereafter, subproperties need only be named, not qualified with owning types, but those subproperties must exist on the preceding property's value type. A slightly more verbose form that qualifies subsequent subproperty owning types is also acceptable; for example, "(Rectangle.Fill).(SolidColorBrush.Color)".