For All CommunityToolkit.Maui.Behaviors, Ensure BindingContext Is Automatically Set to the Attached View's BindingContext#1791
Conversation
pictos
left a comment
There was a problem hiding this comment.
it looks a lot of work, great that you could fit it soo fast! I've some points there
|
Does the BaseBehavior need to account for being attached to multiple Since specifically the |
Good question - yes! I followed the existing pattern I found in |
Co-authored-by: Pedro Jesus <[email protected]>
…ttps://github.com/CommunityToolkit/Maui into Update-All-Behaviors-to-Inherit-from-`BaseBehavior`
|
Ok gang! I think this is ready to go. I refactored a couple things just now:
|
|
@brminnick @pictos |
Description of Change
The goal of this Pull Request is to ensure that every
BehaviorinCommunityToolkit.Maui.Behaviorautomatically set's the itsBindingContextto match theBindingContextof the attachedView.This PR creates/updates the following classes/interfaces:
ICommunityToolkitBehavior- an interface meant for internal consumption, used to align the functionality ofBaseBehaviorandBasePlatformBehaviorBaseBehavior : ICommunityToolkitBehaviorBaseBehaviornow implementsICommunityToolkitBehaviorBasePlatformBehavior<TView> : BasePlatformBehavior<TView, PlatformView> where TView : ElementPlatformViewfor each operating systemBasePlatformBehavior<TView, TPlatformView> : PlatformBehavior<TView, TPlatformView>, ICommunityToolkitBehavior<TView> where TView : Element where TPlatformView : classLinked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
The unit tests for
BasePlatformBehaviorcan't testOnAttachedTo()becauseOnAttachedTo()is only called in platform-specific code forMicrosoft.Maui.Controls.PlatformBehavior.I also updated the Unit Tests to use Collection Expressions for a small performance bump.