[Community Toolkit Feature Promotion] Expand WeakEventManager to Support Delegate
#2703
Labels
fixed-in-6.0.101-preview.11.3
Look for this fix in 6.0.101-preview.11.3!
fixed-in-6.0.200-preview.12
Look for this fix in 6.0.200-preview.12!
proposal/open
t/enhancement ☀️
New feature or request
WeakEventManager
Microsoft.Maui.Controls.WeakEventManger
only supportsevent EventHandler
.It does not currently work with the other
event
types in C#, likeDelegate
.This means that
Microsoft.Maui.Controls.WeakEventManger
does not currently work for the most commonDelegate
event,INotifyPropertyChanged.PropertyChanged
.Because
EventHandler
is aDelegate
, we can expandWeakEventManager
, adding support forDelegate
without any breaking changes.Working Example
For
EventHandler
events,Microsoft.Maui.Controls.WeakEventManger
works great!Non-Working Example
For
delegate
events,Microsoft.Maui.Controls.WeakEventManger
is not compatible.Xamarin Community Toolkit,
DelegateWeakEventManager
The
Xamarin.CommunityToolkit
has expanded onWeakEventManager
, adding support fordelegate
events:https://docs.microsoft.com/xamarin/community-toolkit/helpers/delegateweakeventmanager?WT.mc_id=mobile-43581-bramin
This feature was named
DelegateWeakEventManager
to avoid a name-collision withWeakEventManager
despite providing (almost) the exact same feature set; the only difference is the additional support fordelegate
events.The Xamarin Community Toolkit has included this expanded WeakEventManager since v1.0.0-pre4 released on October 21, 2020.
We currently have an open proposal to add this functionality to Maui Community Toolkit, but we'd prefer to promote this feature into the official .NET MAUI library.
API Changes
WeakEventManager
Methods
Current
The current implementation only supports
EventHandler
Updated
The updated implementation adds support for
Delegate
Scenarios
C# Example
The most common usage of a
delegate
event is implementingINotifyPropertyChanged
:XAML Example
N/A
CSS Example
N/A
Backward Compatibility
Because
EventHandler
is aDelegate
, this update is completely backwards compatible and does not introduce any breaking changes.Minimum API levels? None
Breaking changes? None
Unsupported platforms? None
Difficulty : Low
I am happy to open a PR to implement this feature
The text was updated successfully, but these errors were encountered: