Skip to content

Commit 60d61ad

Browse files
Clean-up some issues with WeakEventListener Usage, make OnEventAction lambda's static
See #3029 (comment) and MicrosoftDocs/WindowsCommunityToolkitDocs#262 (comment)
1 parent 70f7ab8 commit 60d61ad

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Core/RotatorTile/RotatorTile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private void OnCollectionChanged(object oldValue, object newValue)
440440
var incc = (INotifyCollectionChanged)newValue;
441441
_inccWeakEventListener = new WeakEventListener<RotatorTile, object, NotifyCollectionChangedEventArgs>(this)
442442
{
443-
OnEventAction = (instance, source, eventArgs) => instance.Incc_CollectionChanged(source, eventArgs),
443+
OnEventAction = static (instance, source, eventArgs) => instance.Incc_CollectionChanged(source, eventArgs),
444444
OnDetachAction = (listener) => incc.CollectionChanged -= listener.OnEvent
445445
};
446446
incc.CollectionChanged += _inccWeakEventListener.OnEvent;

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/InterspersedObservableCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public InterspersedObservableCollection(object itemsSource)
6262
{
6363
var weakPropertyChangedListener = new WeakEventListener<InterspersedObservableCollection, object, NotifyCollectionChangedEventArgs>(this)
6464
{
65-
OnEventAction = (instance, source, eventArgs) => instance.ItemsSource_CollectionChanged(source, eventArgs),
65+
OnEventAction = static (instance, source, eventArgs) => instance.ItemsSource_CollectionChanged(source, eventArgs),
6666
OnDetachAction = (weakEventListener) => notifier.CollectionChanged -= weakEventListener.OnEvent // Use Local Reference Only
6767
};
6868
notifier.CollectionChanged += weakPropertyChangedListener.OnEvent;

Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public IList Source
9797
new WeakEventListener<AdvancedCollectionView, object, NotifyCollectionChangedEventArgs>(this)
9898
{
9999
// Call the actual collection changed event
100-
OnEventAction = (source, changed, arg3) => SourceNcc_CollectionChanged(source, arg3),
100+
OnEventAction = static (instance, source, arg3) => instance.SourceNcc_CollectionChanged(source, arg3),
101101

102102
// The source doesn't exist anymore
103103
OnDetachAction = (listener) => sourceNcc.CollectionChanged -= _sourceWeakEventListener.OnEvent

Microsoft.Toolkit.Uwp.UI/Triggers/FullScreenModeStateTrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public FullScreenModeStateTrigger()
2323
var weakEvent =
2424
new WeakEventListener<FullScreenModeStateTrigger, ApplicationView, object>(this)
2525
{
26-
OnEventAction = (instance, source, eventArgs) => instance.FullScreenModeTrigger_VisibleBoundsChanged(source, eventArgs),
26+
OnEventAction = static (instance, source, eventArgs) => instance.FullScreenModeTrigger_VisibleBoundsChanged(source, eventArgs),
2727
OnDetachAction = (weakEventListener) => ApplicationView.GetForCurrentView().VisibleBoundsChanged -= weakEventListener.OnEvent
2828
};
2929
ApplicationView.GetForCurrentView().VisibleBoundsChanged += weakEvent.OnEvent;

Microsoft.Toolkit.Uwp.UI/Triggers/IsNullOrEmptyStateTrigger.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ private static void OnValuePropertyChanged(DependencyObject d, DependencyPropert
4747
var valNotifyCollection = val as INotifyCollectionChanged;
4848
if (valNotifyCollection != null)
4949
{
50-
var weakEvent = new WeakEventListener<INotifyCollectionChanged, object, NotifyCollectionChangedEventArgs>(valNotifyCollection)
50+
var weakEvent = new WeakEventListener<IsNullOrEmptyStateTrigger, object, NotifyCollectionChangedEventArgs>(obj)
5151
{
52-
OnEventAction = (instance, source, args) => obj.SetActive(IsNullOrEmpty(instance)),
52+
OnEventAction = static (instance, source, args) => instance.SetActive(IsNullOrEmpty(source)),
5353
OnDetachAction = (weakEventListener) => valNotifyCollection.CollectionChanged -= weakEventListener.OnEvent
5454
};
5555

@@ -61,9 +61,9 @@ private static void OnValuePropertyChanged(DependencyObject d, DependencyPropert
6161
var valObservableVector = val as IObservableVector<object>;
6262
if (valObservableVector != null)
6363
{
64-
var weakEvent = new WeakEventListener<IObservableVector<object>, object, IVectorChangedEventArgs>(valObservableVector)
64+
var weakEvent = new WeakEventListener<IsNullOrEmptyStateTrigger, object, IVectorChangedEventArgs>(obj)
6565
{
66-
OnEventAction = (instance, source, args) => obj.SetActive(IsNullOrEmpty(instance)),
66+
OnEventAction = static (instance, source, args) => instance.SetActive(IsNullOrEmpty(source)),
6767
OnDetachAction = (weakEventListener) => valObservableVector.VectorChanged -= weakEventListener.OnEvent
6868
};
6969

@@ -75,9 +75,9 @@ private static void OnValuePropertyChanged(DependencyObject d, DependencyPropert
7575
var valObservableMap = val as IObservableMap<object, object>;
7676
if (valObservableMap != null)
7777
{
78-
var weakEvent = new WeakEventListener<IObservableMap<object, object>, object, IMapChangedEventArgs<object>>(valObservableMap)
78+
var weakEvent = new WeakEventListener<IsNullOrEmptyStateTrigger, object, IMapChangedEventArgs<object>>(obj)
7979
{
80-
OnEventAction = (instance, source, args) => obj.SetActive(IsNullOrEmpty(instance)),
80+
OnEventAction = static (instance, source, args) => instance.SetActive(IsNullOrEmpty(source)),
8181
OnDetachAction = (weakEventListener) => valObservableMap.MapChanged -= weakEventListener.OnEvent
8282
};
8383

Microsoft.Toolkit.Uwp.UI/Triggers/NetworkConnectionStateTrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public NetworkConnectionStateTrigger()
2525
var weakEvent =
2626
new WeakEventListener<NetworkConnectionStateTrigger, object>(this)
2727
{
28-
OnEventAction = (instance, source) => NetworkInformation_NetworkStatusChanged(source),
28+
OnEventAction = static (instance, source) => instance.NetworkInformation_NetworkStatusChanged(source),
2929
OnDetachAction = (weakEventListener) => NetworkInformation.NetworkStatusChanged -= weakEventListener.OnEvent
3030
};
3131
NetworkInformation.NetworkStatusChanged += weakEvent.OnEvent;

Microsoft.Toolkit.Uwp.UI/Triggers/UserInteractionModeStateTrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public UserInteractionModeStateTrigger()
2424
var weakEvent =
2525
new WeakEventListener<UserInteractionModeStateTrigger, object, WindowSizeChangedEventArgs>(this)
2626
{
27-
OnEventAction = (instance, source, eventArgs) => UserInteractionModeTrigger_SizeChanged(source, eventArgs),
27+
OnEventAction = static (instance, source, eventArgs) => instance.UserInteractionModeTrigger_SizeChanged(source, eventArgs),
2828
OnDetachAction = (weakEventListener) => Window.Current.SizeChanged -= weakEventListener.OnEvent
2929
};
3030
Window.Current.SizeChanged += weakEvent.OnEvent;

0 commit comments

Comments
 (0)