Cannot Animate Immutable object RRS feed

  • Question

  • I have a path in my app, that on mouse over, i want to animate the color. I have this working fine, however, i recenly moved all my app's coors to a seperate assembly because i want to use themes. I changed my animation to reference the color in the other assembly and that all works fine. Now when i mouse over i get this error:
    Cannot animate '(0).(1)' on an immutable object instance

    Solutions i have seen create a clone of the object to animate, but i am not sure how to do that. Any help would be great!
    Here is my path:
    <Path HorizontalAlignment="Right" Margin="0,0.5,61.755,0" VerticalAlignment="Top" Width="170.5" Height="123.25" Fill="{DynamicResource {x:Static res:Resources.AvidPrimaryColor4}}" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="0" Data="M436.25,123.5 L493.75,71.5 C445.94562,24.49702 388.61817,2.0195628 323.25,0.25 L323.25,75 C366.10246,76.083692 403.78435,91.016389 436.25,123.5 z" x:Name="pathOuterProcess" RenderTransformOrigin="0.5,0.5" Opacity="0.5" MouseEnter="pathOuterProcess_MouseEnter" MouseLeftButtonDown="pathOuterProcess_MouseLeftButtonDown"/>

    Notice the "Fill" references my assembly. Here is the Animation with a similiar reference:

    <Storyboard x:Key="ORProcessMouseEnter">
    <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="pathOuterProcess" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
    <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="{DynamicResource {x:Static res:Resources.AvidNavigationMouseOverColor}}"/>
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="pathOuterProcess" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
    <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.1"/>
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="pathOuterProcess" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
    <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.1"/>
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="pathOuterProcess" Storyboard.TargetProperty="(UIElement.Opacity)">
    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.6"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0.75"/>
    Thursday, March 20, 2008 3:41 PM

All replies

  • Hi,

    I'm trying to reproduce the error you see, and I have a question: what's the type of the AvidPrimaryColor4 property? Is it a Color, Brush or a ResourceKey?

    Would it be possible to send me a sample project showing this behavior?

    - Adrian

    - Adrian Vinca [MSFT]
    Content is provided "AS IS" with no warranties and confers no rights.
    Saturday, March 22, 2008 12:24 AM
  • Yes i can, just give me a little time to put it together. How would you like me to get the project to you?
    Tuesday, March 25, 2008 1:40 PM
  • Could you e-mail it to me at adrianv at microsoft dot com?

    - Adrian
    Wednesday, March 26, 2008 7:34 PM
  • Any updates on this? I have the same error.

    The strange thing is my animation works fine in the Blend designer window. Just when I run it as an application it crashes with the exception above.

    Here is the code:

            <Storyboard x:Key="Storyboard1">
                <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SecondsLabel" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF000000"/>
                    <SplineColorKeyFrame KeyTime="00:00:00.7000000" Value="#FFFF0000"/>
            <EventTrigger RoutedEvent="TextBoxBase.TextChanged" SourceName="SecondsValue">
                <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>

    Also, SecondsLabel is NOT databound:

         <TextBlock x:Name="SecondsBlock" Grid.Row="1" Grid.Column="1"><InlineUIContainer>
                    <TextBox Text="{Binding Path=TimeElapsedMonitor.TimeElapsed.Seconds, Mode=OneWay, ElementName=UserControl}" HorizontalAlignment="Left" d:LayoutOverrides="VerticalAlignment, Height" x:Name="SecondsValue" VerticalAlignment="Top"/>
                    <TextBlock x:Name="SecondsLabel" TextWrapping="Wrap" Text=" Seconds"/>

    Monday, September 22, 2008 10:11 AM
  • I also have this problem

    The funny thing is that if you also move the object a bit while changing its color it doesn't bite you at all. 

    I have proof of this. 

    Compare the two animation codes:

    The first one that throws that exception:


    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectEmail">
    				<SplineColorKeyFrame KeyTime="0" Value="#CDE6D6E8"/>
    				<EasingColorKeyFrame KeyTime="0:0:0.2" Value="#CD36103B"/>


    This one doesn't harm you at all!!


    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="Alef_Back">
    				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.309"/>
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="Alef_Back">
    				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-12.5"/>
    			<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Alef_Back">
    				<EasingColorKeyFrame KeyTime="0:0:0.2" Value="#FFFFFF90"/>



    My problem was not caused by the rectangle object

    Turns out I was also changing the foregraoud color of a TextBlock as well. That was the reason it caused all those troubles.

    Changing the TextBlock to label might work out.

    Saturday, May 28, 2011 5:42 AM
  • Because you have not set the color attribute.  The brush is not define.  So that the animation of color can not work . 
    Tuesday, January 8, 2013 9:41 AM