PlatformBehavior is not attached to to the view if the view is in a header or a footer
Description
Greetings, I have encountered a bug where PlatformBehaviors are not being attached to views that exist in footers and headers. Basically, an instance of Behavior class gets its OnAttachedTo method called, however, the PlatformBehavior<TView, TPlatformView> OnAttachedTo method is not called in this case. I have tested this on Android and iOS platforms.
I have a reason to believe, this happens due to
protected sealed override void OnAttachedTo(TView bindable)
{
if (bindable is VisualElement ve)
{
ve.Loaded += OnLoaded;
ve.Unloaded += OnUnloaded;
}
else
{
if (bindable.Handler != null)
FireAttachedTo(bindable);
bindable.HandlerChanged += OnHandlerChanged;
}
}
As components inside ListView.Footer and ListView.Header never get their Loaded events called.
I attach the sample for reproduction
Steps to Reproduce
- Open the sample
- Put breakpoints in MyBehavior.cs line 21 and line 30
- Verify that MainPage.xaml has a ListView wirh Header and Footer and that one of them has a MyBehavior and the other MyPlatformBehavior
- Build and deploy
- See that breakpoint in line 30 is never hit and Console only shows that Behavior is attached
Link to public reproduction project repository
https://github.com/era-maui/HeaderSample
Version with bug
8.0.91 SR9.1
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
No response
Affected platforms
Android, iOS
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
I can repro this issue at Android platform on the latest 17.12.0 preview 3(8.0.92 & 8.0.91 & 8.0.90).
I am also experiencing this, bumping ☝️
@dalux-era This issue does not occur with the CollectionView control. You may consider using CollectionView instead of ListView, especially since ListView is planned to be deprecated in .NET 10.