I have made progress on translating my skew animation to the double animation class. The only problem left is when the animation is called by the dispatch timer, an error is thrown. The error is as follows...
Cannot animate the 'AngleX' property on 'System.Windows.Media.MatrixTransform' because the object is sealed or frozen.
How would i overcome this error so that the animation can work?
public static void Grass(Canvas canvas, int boundry)
{
foreach (var element in canvas.Children.OfType<Image>())
{
if (element.Name == "GrassForeground" || element.Name == "GrassBackground")
{
var skewGrass = new DoubleAnimation
{
From = 0,
To = 10,
EasingFunction = new BackEase(),
AutoReverse = true
};
var transform = (MatrixTransform)element.RenderTransform;
transform.BeginAnimation(SkewTransform.AngleXProperty, skewGrass);
}
}
}
Try this below, or do you have a special reason to use MatrixTransform?
Your
element
ALREADY have aRenderTransform
property assign, but this object is a frozenSkewTransform
object. You can't change it's AngleX property since it is already rendered.If you assign the RenderTransform property to a
new SkewTransform()
thisSkewTransform
won't be frozen an can be animated.Here is a complete explanation : Freezable Objects Overview on MSDN