-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WeakEventManager/WeakEventListener #404
Comments
Was looking a bit more into this, as I think it'd make sense to not port the Windows Community Toolkit one either forward but instead add that (or similar code here). Looking at the MAUI one, I believe they both service different purposes, so there may be a need for two different APIs/helpers here.
So, I think both patterns are required for different scenarios? |
Was just wondering if we could improve upon the implementation from the WCT and simplify its usage: var inpc = rowGroupInfo.CollectionViewGroup as INotifyPropertyChanged;
var weakPropertyChangedListener = new WeakEventListener<DataGrid, object, PropertyChangedEventArgs>(this) {
OnEventAction = static (instance, source, eventArgs) => instance.CollectionViewGroup_PropertyChanged(source, eventArgs),
OnDetachAction = (weakEventListener) => inpc.PropertyChanged -= weakEventListener.OnEvent // Use Local References Only
}
inpc.PropertyChanged += weakPropertyChangedListener.OnEvent to this: rowGroupInfo.CollectionViewGroup.PropertyChanged +=
(new WeakEventListener<DataGrid, object, PropertyChangedEventArgs>(this) {
OnEventAction = static (@this, source, eventArgs) => @this.CollectionViewGroup_PropertyChanged(source, eventArgs),
OnDetachAction = static (source, listener) => source.PropertyChanged -= listener.OnEvent
}).OnEvent; Basically add the source as a parameter on the (Or is this still going to capture the |
Overview
A class for weakly subscribing to events is a useful concept that has been implemented many times in various projects.
I currently use Xamarin Forms with Xamarin Community Toolkit, and rely on the
ObservableObject
implementation that usesWeakEventManager
forINotifyPropertyChanged.PropertyChanged
.Maui Community Toolkit however does not have its own
ObservableObject
, instead directing people to use the one here (an idea I fully support). However the one here does not support weak subscribing (because there is noWeakEventManager
).I propose adding
WeakEventManager
- probably the one one currently implemented in Maui (https://github.com/dotnet/maui/blob/aa2d11137e8b3226d85a39da4f605bf26ab42aa0/src/Core/src/WeakEventManager.cs), and then adding a way forObservableObejct
to (optionally) use it.(I have a separate issue for that: #80)
API breakdown
(Copied from Maui)
Usage example
Breaking change?
No
Alternatives
There is a proposal to just add this to the BCL:
dotnet/runtime#61517
Additional context
No response
Help us help you
No, just wanted to propose this.
If using the Maui one unchanged is desirable, I'd be able to make such a PR.
The text was updated successfully, but these errors were encountered: