Take the 2-minute tour ×

I have the following XAML:

    <SolidColorBrush x:Key="Brush"></SolidColorBrush>

    <Style TargetType="{x:Type StackPanel}" x:Key="ColourChangingStyle">
        <Setter Property="Background" Value="{StaticResource Brush}" />

            <DataTrigger Binding="{Binding Path='Stage'}" Value="1">
                            <ColorAnimation Storyboard.Target="{StaticResource Brush}"
                              Storyboard.TargetProperty="Color" From="{StaticResource FirstColor}" To="{StaticResource FinishedColor}" Duration="0:0:10" BeginTime="0:0:0"/>

<StackPanel x:Name="InfoPanel" Orientation="Vertical"  Margin="1,2" Style="{DynamicResource ColourChangingStyle}">

And I keep getting the same error that:

Cannot animate 'Color' on an immutable object instance

which is the brush. I looked up the problem, and believe that it's something to do with the binding the brush to the StackPanel making it unavailable to alter later.

Is there any way around this, I literally have no clue what my other options for the same effect are without hardcoding colors in, and doing all the events in code.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

It seems that you can not animate a Brush in Resources with Storyboard.Target. But you can set the Background of your Style (you have done this already) and animate this property.

<ColorAnimation Storyboard.TargetProperty="Background.Color"
                From="{StaticResource FirstColor}"
                To="{StaticResource FinishedColor}" 
share|improve this answer
This worked perfectly well. Thank you. –  Sean Jan 18 '13 at 9:21

Your Answer


