@@ -53,7 +53,7 @@ public static ImplicitAnimationSet GetShowAnimations(UIElement element)
5353
5454 if ( collection is null )
5555 {
56- element . SetValue ( ShowAnimationsProperty , collection = new ( ) ) ;
56+ element . SetValue ( ShowAnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
5757 }
5858
5959 return collection ;
@@ -80,7 +80,7 @@ public static ImplicitAnimationSet GetHideAnimations(UIElement element)
8080
8181 if ( collection is null )
8282 {
83- element . SetValue ( HideAnimationsProperty , collection = new ( ) ) ;
83+ element . SetValue ( HideAnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
8484 }
8585
8686 return collection ;
@@ -107,7 +107,7 @@ public static ImplicitAnimationSet GetAnimations(UIElement element)
107107
108108 if ( collection is null )
109109 {
110- element . SetValue ( AnimationsProperty , collection = new ( ) ) ;
110+ element . SetValue ( AnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
111111 }
112112
113113 return collection ;
@@ -145,15 +145,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
145145 oldCollection . AnimationsChanged -= OnAnimationsChanged ;
146146 }
147147
148- if ( d is UIElement element &&
149- e . NewValue is ImplicitAnimationSet collection )
148+ if ( d is UIElement element )
150149 {
151- collection . ParentReference = new ( element ) ;
152- collection . AnimationsChanged -= OnAnimationsChanged ;
153- collection . AnimationsChanged += OnAnimationsChanged ;
150+ if ( e . NewValue is ImplicitAnimationSet collection )
151+ {
152+ collection . ParentReference = new ( element ) ;
153+ collection . AnimationsChanged -= OnAnimationsChanged ;
154+ collection . AnimationsChanged += OnAnimationsChanged ;
154155
155- ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
156- ElementCompositionPreview . SetImplicitShowAnimation ( element , collection . GetCompositionAnimationGroup ( element ) ) ;
156+ ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
157+ ElementCompositionPreview . SetImplicitShowAnimation ( element , collection . GetCompositionAnimationGroup ( element ) ) ;
158+ }
159+ else
160+ {
161+ ElementCompositionPreview . SetImplicitShowAnimation ( element , null ) ;
162+ }
157163 }
158164 }
159165
@@ -179,15 +185,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
179185 oldCollection . AnimationsChanged -= OnAnimationsChanged ;
180186 }
181187
182- if ( d is UIElement element &&
183- e . NewValue is ImplicitAnimationSet collection )
188+ if ( d is UIElement element )
184189 {
185- collection . ParentReference = new ( element ) ;
186- collection . AnimationsChanged -= OnAnimationsChanged ;
187- collection . AnimationsChanged += OnAnimationsChanged ;
190+ if ( e . NewValue is ImplicitAnimationSet collection )
191+ {
192+ collection . ParentReference = new ( element ) ;
193+ collection . AnimationsChanged -= OnAnimationsChanged ;
194+ collection . AnimationsChanged += OnAnimationsChanged ;
188195
189- ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
190- ElementCompositionPreview . SetImplicitHideAnimation ( element , collection . GetCompositionAnimationGroup ( element ) ) ;
196+ ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
197+ ElementCompositionPreview . SetImplicitHideAnimation ( element , collection . GetCompositionAnimationGroup ( element ) ) ;
198+ }
199+ else
200+ {
201+ ElementCompositionPreview . SetImplicitHideAnimation ( element , null ) ;
202+ }
191203 }
192204 }
193205
@@ -213,15 +225,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
213225 oldCollection . AnimationsChanged -= OnAnimationsChanged ;
214226 }
215227
216- if ( d is UIElement element &&
217- e . NewValue is ImplicitAnimationSet collection )
228+ if ( d is UIElement element )
218229 {
219- collection . ParentReference = new ( element ) ;
220- collection . AnimationsChanged -= OnAnimationsChanged ;
221- collection . AnimationsChanged += OnAnimationsChanged ;
230+ if ( e . NewValue is ImplicitAnimationSet collection )
231+ {
232+ collection . ParentReference = new ( element ) ;
233+ collection . AnimationsChanged -= OnAnimationsChanged ;
234+ collection . AnimationsChanged += OnAnimationsChanged ;
222235
223- ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
224- ElementCompositionPreview . GetElementVisual ( element ) . ImplicitAnimations = collection . GetImplicitAnimationCollection ( element ) ;
236+ ElementCompositionPreview . SetIsTranslationEnabled ( element , true ) ;
237+ ElementCompositionPreview . GetElementVisual ( element ) . ImplicitAnimations = collection . GetImplicitAnimationCollection ( element ) ;
238+ }
239+ else
240+ {
241+ ElementCompositionPreview . GetElementVisual ( element ) . ImplicitAnimations = null ;
242+ }
225243 }
226244 }
227245 }
0 commit comments