diff --git a/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs b/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs
index a35edc2572..4d53fdaea4 100644
--- a/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs
+++ b/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs
@@ -99,10 +99,10 @@ namespace Perspex.Markup.Data.Plugins
if (inpc != null)
{
- //WeakSubscriptionManager.Unsubscribe(
- // inpc,
- // nameof(inpc.PropertyChanged),
- // this);
+ WeakSubscriptionManager.Unsubscribe(
+ inpc,
+ nameof(inpc.PropertyChanged),
+ this);
}
}
diff --git a/src/Perspex.Base/Utilities/IWeakSubscriber.cs b/src/Perspex.Base/Utilities/IWeakSubscriber.cs
new file mode 100644
index 0000000000..454c43c17f
--- /dev/null
+++ b/src/Perspex.Base/Utilities/IWeakSubscriber.cs
@@ -0,0 +1,21 @@
+// Copyright (c) The Perspex Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System;
+
+namespace Perspex.Utilities
+{
+ ///
+ /// Defines a listener to a event subscribed vis the .
+ ///
+ /// The type of the event arguments.
+ public interface IWeakSubscriber where T : EventArgs
+ {
+ ///
+ /// Invoked when the subscribed event is raised.
+ ///
+ /// The event sender.
+ /// The event arguments.
+ void OnEvent(object sender, T e);
+ }
+}
diff --git a/src/Perspex.Base/Utilities/WeakSubscriptionManager.cs b/src/Perspex.Base/Utilities/WeakSubscriptionManager.cs
index 9adb9ff3ca..d307aad004 100644
--- a/src/Perspex.Base/Utilities/WeakSubscriptionManager.cs
+++ b/src/Perspex.Base/Utilities/WeakSubscriptionManager.cs
@@ -1,41 +1,89 @@
-using System;
+// Copyright (c) The Perspex Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System;
using System.Collections.Generic;
-using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
namespace Perspex.Utilities
{
+ ///
+ /// Manages subscriptions to events using weak listeners.
+ ///
public static class WeakSubscriptionManager
{
- static class SubscriptionTypeStorage
+ ///
+ /// Subscribes to an event on an object using a weak subscription.
+ ///
+ /// The type of the event arguments.
+ /// The event source.
+ /// The name of the event.
+ /// The subscriber.
+ public static void Subscribe(object target, string eventName, IWeakSubscriber subscriber)
+ where T : EventArgs
{
- public static readonly ConditionalWeakTable