C# Class MahApps.Metro.Controls.PropertyChangeNotifier

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/
Inheritance: System.Windows.DependencyObject, IDisposable
Show file Open project: MahApps/MahApps.Metro Class Usage Examples

Public Properties

Property Type Description
ValueProperty System.Windows.DependencyProperty

Private Properties

Property Type Description
OnPropertyChanged void

Public Methods

Method Description
Dispose ( ) : void
PropertyChangeNotifier ( DependencyObject propertySource, DependencyProperty property ) : System
PropertyChangeNotifier ( DependencyObject propertySource, PropertyPath property ) : System
PropertyChangeNotifier ( DependencyObject propertySource, string path ) : System

Private Methods

Method Description
OnPropertyChanged ( DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e ) : void

Method Details

Dispose() public method

public Dispose ( ) : void
return void

PropertyChangeNotifier() public method

public PropertyChangeNotifier ( DependencyObject propertySource, DependencyProperty property ) : System
propertySource System.Windows.DependencyObject
property System.Windows.DependencyProperty
return System

PropertyChangeNotifier() public method

public PropertyChangeNotifier ( DependencyObject propertySource, PropertyPath property ) : System
propertySource System.Windows.DependencyObject
property System.Windows.PropertyPath
return System

PropertyChangeNotifier() public method

public PropertyChangeNotifier ( DependencyObject propertySource, string path ) : System
propertySource System.Windows.DependencyObject
path string
return System

Property Details

ValueProperty public static property

Identifies the Value dependency property
public static DependencyProperty,System.Windows ValueProperty
return System.Windows.DependencyProperty