diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/CompositionExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/CompositionExtensions.cs
index 16f0525b369..521d69ea2a9 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/CompositionExtensions.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/CompositionExtensions.cs
@@ -176,6 +176,8 @@ public static void StartAnimation(this CompositionObject compObject, string prop
/// The easing function to use when interpolating between frames.
public static void InsertExpressionKeyFrame(this KeyFrameAnimation keyframeAnimation, float normalizedProgressKey, ExpressionNode expressionNode, CompositionEasingFunction easing = null)
{
+ expressionNode.ClearReferenceInfo();
+
keyframeAnimation.InsertExpressionKeyFrame(normalizedProgressKey, expressionNode.ToExpressionString(), easing);
expressionNode.SetAllParameters(keyframeAnimation);
@@ -252,6 +254,7 @@ private static ExpressionAnimation CreateExpressionAnimationFromNode(Compositor
// Only create a new animation if this node hasn't already generated one before, so we don't have to re-parse the expression string.
if (expressionNode.ExpressionAnimation == null)
{
+ expressionNode.ClearReferenceInfo();
expressionNode.ExpressionAnimation = compositor.CreateExpressionAnimation(expressionNode.ToExpressionString());
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs
index e02d4500201..e864b725a03 100644
--- a/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs
@@ -260,6 +260,20 @@ internal string ToExpressionString()
return ToExpressionStringInternal();
}
+ ///
+ /// Clears the reference information.
+ ///
+ /// Reference and paramName can't both be null
+ internal void ClearReferenceInfo()
+ {
+ _objRefList = null;
+ ParamName = null;
+ foreach (var child in Children)
+ {
+ child.ClearReferenceInfo();
+ }
+ }
+
///
/// Ensures the reference information.
///