@@ -190,13 +190,13 @@ select handler.Value
190
190
// For instance, a DataTemplate in a resource dictionary may mark the type as updated in `updatedTypes`
191
191
// but it will not be considered as a new type even if "CreateNewOnMetadataUpdate" was set.
192
192
193
- return ( fe , ImmutableArray < ElementUpdateHandlerActions > . Empty , liveType ) ;
193
+ return ( fe , [ ] , liveType ) ;
194
194
}
195
195
else
196
196
{
197
- return ! handlers . IsDefaultOrEmpty || mappedType is not null
197
+ return ( ! handlers . IsDefaultOrEmpty || mappedType is not null )
198
198
? ( fe , handlers , mappedType )
199
- : default ;
199
+ : ( null , [ ] , null ) ;
200
200
}
201
201
} ,
202
202
parentKey : default ) ;
@@ -208,21 +208,26 @@ select handler.Value
208
208
// or replace the element with a new one
209
209
foreach ( var ( element , elementHandlers , elementMappedType ) in instancesToUpdate )
210
210
{
211
+ if ( element is null )
212
+ {
213
+ continue ;
214
+ }
215
+
211
216
// Action: ElementUpdate
212
217
// This is invoked for each existing element that is in the tree that needs to be replaced
213
218
foreach ( var elementHandler in elementHandlers )
214
219
{
215
220
elementHandler ? . ElementUpdate ( element , updatedTypes ) ;
221
+ }
216
222
217
- if ( elementMappedType is not null )
223
+ if ( elementMappedType is not null )
224
+ {
225
+ if ( _log . IsEnabled ( LogLevel . Trace ) )
218
226
{
219
- if ( _log . IsEnabled ( LogLevel . Trace ) )
220
- {
221
- _log . Error ( $ "Updating element [{ element } ] to [{ elementMappedType } ]") ;
222
- }
223
-
224
- ReplaceViewInstance ( element , elementMappedType , elementHandler ) ;
227
+ _log . Error ( $ "Updating element [{ element } ] to [{ elementMappedType } ]") ;
225
228
}
229
+
230
+ ReplaceViewInstance ( element , elementMappedType , elementHandlers , updatedTypes ) ;
226
231
}
227
232
}
228
233
@@ -408,7 +413,7 @@ private static void UpdateResourceDictionaries(List<Uri> updatedDictionaries, Re
408
413
}
409
414
#endif
410
415
411
- private static void ReplaceViewInstance ( UIElement instance , Type replacementType , ElementUpdateAgent . ElementUpdateHandlerActions ? handler = default , Type [ ] ? updatedTypes = default )
416
+ private static void ReplaceViewInstance ( UIElement instance , Type replacementType , in ImmutableArray < ElementUpdateHandlerActions > handlers , Type [ ] updatedTypes )
412
417
{
413
418
if ( replacementType . GetConstructor ( Array . Empty < Type > ( ) ) is { } creator )
414
419
{
@@ -429,11 +434,17 @@ private static void ReplaceViewInstance(UIElement instance, Type replacementType
429
434
oldStore . ClonePropertiesToAnotherStoreForHotReload ( newStore ) ;
430
435
#endif
431
436
432
- handler ? . BeforeElementReplaced ( instanceFE , newInstanceFE , updatedTypes ) ;
437
+ foreach ( var handler in handlers )
438
+ {
439
+ handler . BeforeElementReplaced ( instanceFE , newInstanceFE , updatedTypes ) ;
440
+ }
433
441
434
442
SwapViews ( instanceFE , newInstanceFE ) ;
435
443
436
- handler ? . AfterElementReplaced ( instanceFE , newInstanceFE , updatedTypes ) ;
444
+ foreach ( var handler in handlers )
445
+ {
446
+ handler . AfterElementReplaced ( instanceFE , newInstanceFE , updatedTypes ) ;
447
+ }
437
448
}
438
449
}
439
450
else
0 commit comments