// static method invoked when Group property has changed value // here we need to attach event handler defined if DPGroup, so it will fire from inside Group property, // when Group.MyProperty1 will change value static void OnGroupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DPTest control = (DPTest)d; DPGroup oldGroup = e.OldValue as DPGroup; // removing event handler from prevoius instance of DBGroup if (oldGroup != null) { oldGroup.PropertyChanged -= new PropertyChangedEventHandler(control.group_PropertyChanged); } DPGroup newGroup = e.NewValue as DPGroup; // adding event handler to new instance of DBGroup if (newGroup != null) { newGroup.PropertyChanged += new PropertyChangedEventHandler(control.group_PropertyChanged); } DPTest g = d as DPTest; if (g != null) { control.UpdateTextBox(); } }
// static method invoked when MyProperty1 has changed value static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DPGroup g = d as DPGroup; if (g != null) { g.MyProperty1 = (int)e.NewValue; // invoking event handler, to notify parent class about changed value of DP if (g.PropertyChanged != null) { g.PropertyChanged(g, null); } } }
static void OnGroupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DPTest control = (DPTest)d; DPGroup oldGroup = e.OldValue as DPGroup; if (oldGroup != null) { oldGroup.PropertyChanged -= new PropertyChangedEventHandler(control.group_PropertyChanged); } DPGroup newGroup = e.NewValue as DPGroup; if (newGroup != null) { newGroup.PropertyChanged += new PropertyChangedEventHandler(control.group_PropertyChanged); } control.UpdateTextBox(); }