@@ -53,7 +53,7 @@ public static ImplicitAnimationSet GetShowAnimations(UIElement element)
53
53
54
54
if ( collection is null )
55
55
{
56
- element . SetValue ( ShowAnimationsProperty , collection = new ( ) ) ;
56
+ element . SetValue ( ShowAnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
57
57
}
58
58
59
59
return collection ;
@@ -80,7 +80,7 @@ public static ImplicitAnimationSet GetHideAnimations(UIElement element)
80
80
81
81
if ( collection is null )
82
82
{
83
- element . SetValue ( HideAnimationsProperty , collection = new ( ) ) ;
83
+ element . SetValue ( HideAnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
84
84
}
85
85
86
86
return collection ;
@@ -107,7 +107,7 @@ public static ImplicitAnimationSet GetAnimations(UIElement element)
107
107
108
108
if ( collection is null )
109
109
{
110
- element . SetValue ( AnimationsProperty , collection = new ( ) ) ;
110
+ element . SetValue ( AnimationsProperty , collection = new ImplicitAnimationSet ( ) ) ;
111
111
}
112
112
113
113
return collection ;
@@ -145,15 +145,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
145
145
oldCollection . AnimationsChanged -= OnAnimationsChanged ;
146
146
}
147
147
148
- if ( d is UIElement element &&
149
- e . NewValue is ImplicitAnimationSet collection )
148
+ if ( d is UIElement element )
150
149
{
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 ;
154
155
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
+ }
157
163
}
158
164
}
159
165
@@ -179,15 +185,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
179
185
oldCollection . AnimationsChanged -= OnAnimationsChanged ;
180
186
}
181
187
182
- if ( d is UIElement element &&
183
- e . NewValue is ImplicitAnimationSet collection )
188
+ if ( d is UIElement element )
184
189
{
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 ;
188
195
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
+ }
191
203
}
192
204
}
193
205
@@ -213,15 +225,21 @@ static void OnAnimationsChanged(object sender, EventArgs e)
213
225
oldCollection . AnimationsChanged -= OnAnimationsChanged ;
214
226
}
215
227
216
- if ( d is UIElement element &&
217
- e . NewValue is ImplicitAnimationSet collection )
228
+ if ( d is UIElement element )
218
229
{
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 ;
222
235
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
+ }
225
243
}
226
244
}
227
245
}
0 commit comments