Cannot Animate Immutable object
-
Thursday, March 20, 2008 3:41 PMI 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}}"/>
</ColorAnimationUsingKeyFrames>
<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>
<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>
<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"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
All Replies
-
Saturday, March 22, 2008 12:24 AMHi,
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?
Thanks,
- Adrian
- Adrian Vinca [MSFT]
Content is provided "AS IS" with no warranties and confers no rights. -
Tuesday, March 25, 2008 1:40 PMYes i can, just give me a little time to put it together. How would you like me to get the project to you?
-
Wednesday, March 26, 2008 7:34 PMCould you e-mail it to me at adrianv at microsoft dot com?
Thanks!
- Adrian -
Monday, September 22, 2008 10:11 AMAny 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"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="TextBoxBase.TextChanged" SourceName="SecondsValue">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</UserControl.Triggers>
Also, SecondsLabel is NOT databound:
<Grid>
...
<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"/>
</InlineUIContainer><InlineUIContainer>
<TextBlock x:Name="SecondsLabel" TextWrapping="Wrap" Text=" Seconds"/>
</InlineUIContainer></TextBlock>
...
</Grid>
-
Saturday, May 28, 2011 5:42 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"/> </ColorAnimationUsingKeyFrames>
This one doesn't harm you at all!!
PLEASE HELP!<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="Alef_Back"> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.309"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="Alef_Back"> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-12.5"/> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Alef_Back"> <EasingColorKeyFrame KeyTime="0:0:0.2" Value="#FFFFFF90"/> </ColorAnimationUsingKeyFrames>
UPDATE:
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.
-
Tuesday, January 08, 2013 9:41 AMBecause you have not set the color attribute. The brush is not define. So that the animation of color can not work .

