maui icon indicating copy to clipboard operation
maui copied to clipboard

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

Open dalux-era opened this issue 1 year ago • 2 comments

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

dalux-era avatar Oct 22 '24 07:10 dalux-era

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

jaosnz-rep avatar Oct 22 '24 07:10 jaosnz-rep

I am also experiencing this, bumping ☝️

jurganson avatar Oct 23 '24 10:10 jurganson

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

sheiksyedm avatar May 14 '25 11:05 sheiksyedm