dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.14k stars 1.74k forks source link

PlatformBehavior is not attached to to the view if the view is in a header or a footer #25438

Open era-maui opened 1 day ago

era-maui commented 1 day ago

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

  1. Open the sample
  2. Put breakpoints in MyBehavior.cs line 21 and line 30
  3. Verify that MainPage.xaml has a ListView wirh Header and Footer and that one of them has a MyBehavior and the other MyPlatformBehavior
  4. Build and deploy
  5. 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

jaosnz-rep commented 1 day ago

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).

jurganson commented 8 hours ago

I am also experiencing this, bumping ☝️