Why does a behavior’s CommandParameter or bound item become null or outdated after refreshing or replacing ItemsSource?

Platform: .NET MAUI| Category: Collection View

CollectionView recycles its item containers. When ItemsSource changes, existing visuals may be reused before new bindings are applied. Behaviors that cached item references when they were first attached will then reference stale or null objects.

Fix: Use bindings based on the current BindingContext (such as {Binding .}), avoid storing item references inside the behavior, and reapply or update behaviors when containers are reused.

<local:TapBehavior Command="{Binding TapCommand}"
                   CommandParameter="{Binding .}" />

Share with