This commit is contained in:
GG Z
2025-07-31 20:12:24 +08:00
parent 4f6cd2137c
commit f209e7d3ad
426 changed files with 15854 additions and 6612 deletions

View File

@@ -1,4 +1,4 @@
namespace AntDesign.WPF.Controls
namespace AntDesignWPF.Controls
{
using System;
using System.ComponentModel;
@@ -6,17 +6,15 @@
using System.Windows.Data;
/// <summary>
/// AddValueChanged of dependency property descriptor results in memory leak as you already know.
/// So, as described here, you can create custom class PropertyChangeNotifier to listen
/// to any dependency property changes.
///
/// This class takes advantage of the fact that bindings use weak references to manage associations
/// so the class will not root the object who property changes it is watching. It also uses a WeakReference
/// to maintain a reference to the object whose property it is watching without rooting that object.
/// In this way, you can maintain a collection of these objects so that you can unhook the property
/// change later without worrying about that collection rooting the object whose values you are watching.
///
/// Complete implementation can be found here: http://agsmith.wordpress.com/2008/04/07/propertydescriptor-addvaluechanged-alternative/
///依赖属性描述符的 AddValueChanged 会导致内存泄漏,如您所知。
///因此,如此处所述,您可以创建自定义类 PropertyChangeNotifier 来监听
///到任何依赖属性更改。
///此类利用绑定使用弱引用来管理关联的事实
///因此,该类不会对属性更改它的对象进行 root 权限。它还使用一个 WeakReference
///以维护对它正在监视其属性的对象的引用,而无需对该对象进行 root 设置。
///通过这种方式,您可以维护这些对象的集合,以便可以取消挂钩属性
///稍后更改,而不必担心该集合会对您正在监视其值的对象进行 root。
///完整的实现可以在这里找到http://agsmith.wordpress.com/2008/04/07/propertydescriptor-addvaluechanged-alternative/
/// </summary>
internal sealed class PropertyChangeNotifier : DependencyObject, IDisposable
{