@@ -54,18 +54,22 @@ public AnimationBuilder AppendToBuilder(AnimationBuilder builder, UIElement pare
54
54
{
55
55
static AnimationBuilder ThrowArgumentNullException ( )
56
56
{
57
- throw new ArgumentNullException (
58
- "The target shadow cannot be animated at this time." ) ;
57
+ throw new ArgumentNullException ( "The target shadow cannot be animated at this time." ) ;
59
58
}
60
59
61
60
return ThrowArgumentNullException ( ) ;
62
61
}
63
62
64
63
if ( Target is IAttachedShadow allShadows )
65
64
{
66
- // in this case we'll animate all the shadows being used.
65
+ // In this case we'll animate all the shadows being used
67
66
foreach ( var context in allShadows . EnumerateElementContexts ( ) ) //// TODO: Find better way!!!
68
67
{
68
+ if ( context . Shadow is not DropShadow shadow )
69
+ {
70
+ continue ;
71
+ }
72
+
69
73
NormalizedKeyFrameAnimationBuilder < TKeyFrame > . Composition keyFrameBuilder = new (
70
74
explicitTarget ,
71
75
Delay ?? delayHint ?? DefaultDelay ,
@@ -75,25 +79,18 @@ static AnimationBuilder ThrowArgumentNullException()
75
79
76
80
AppendToBuilder ( keyFrameBuilder , easingTypeHint , easingModeHint ) ;
77
81
78
- CompositionAnimation animation = keyFrameBuilder . GetAnimation ( context . Shadow , out _ ) ;
82
+ CompositionAnimation animation = keyFrameBuilder . GetAnimation ( shadow , out _ ) ;
79
83
80
- builder . ExternalAnimation ( context . Shadow , animation ) ;
84
+ builder . ExternalAnimation ( shadow , animation ) ;
81
85
}
82
86
83
87
return builder ;
84
88
}
85
- else
89
+ else if ( Effects . GetShadow ( ( FrameworkElement ) parent ) is AttachedShadowBase shadowBase &&
90
+ shadowBase . GetElementContext ( ( FrameworkElement ) parent ) . Shadow is DropShadow shadow )
86
91
{
87
- var shadowBase = Effects . GetShadow ( parent as FrameworkElement ) ;
88
- if ( shadowBase == null )
89
- {
90
- static AnimationBuilder ThrowArgumentNullException ( ) => throw new ArgumentNullException ( "The target's shadow is null, make sure to set the Target property to an element with a Shadow" ) ;
91
-
92
- return ThrowArgumentNullException ( ) ;
93
- }
94
-
95
- var shadow = shadowBase . GetElementContext ( ( FrameworkElement ) parent ) . Shadow ;
96
-
92
+ // In this case, the animation is targeting the single shadow attached to the target element.
93
+ // The same checks as before have been performed to ensure that unloading doesn't cause issues.
97
94
NormalizedKeyFrameAnimationBuilder < TKeyFrame > . Composition keyFrameBuilder = new (
98
95
explicitTarget ,
99
96
Delay ?? delayHint ?? DefaultDelay ,
@@ -107,6 +104,8 @@ static AnimationBuilder ThrowArgumentNullException()
107
104
108
105
return builder . ExternalAnimation ( shadow , animation ) ;
109
106
}
107
+
108
+ return builder ;
110
109
}
111
110
}
112
111
}
0 commit comments