You can. At least I did it. You still need to see the pros and cons.
/// Listen for change of the dependency property public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) { //Bind to a depedency property Binding b = new Binding(propertyName) { Source = element }; var prop = System.Windows.DependencyProperty.RegisterAttached( "ListenAttached"+propertyName, typeof(object), typeof(UserControl), new System.Windows.PropertyMetadata(callback)); element.SetBinding(prop, b); }
And now you can call RegisterForNotification to register to notify you of an element property change, for example.
RegisterForNotification("Text", this.txtMain,(d,e)=>MessageBox.Show("Text changed")); RegisterForNotification("Value", this.sliderMain, (d, e) => MessageBox.Show("Value changed"));
See my post here on the same http://amazedsaint.blogspot.com/2009/12/silverlight-listening-to-dependency.html
source share