Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From: <a href="http://msdn.microsoft.com/en-us/library/ms752914.aspx#setting_properties_data_binding" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms752914.aspx#setting_properties_data_binding</a></p> <blockquote> <p>Dependency properties, or the DependencyObject class, <strong>do not natively support INotifyPropertyChanged</strong> for purposes of producing notifications of changes in DependencyObject source property value for data binding operations. For more information on how to create properties for use in data binding that can report changes to a data binding target, see Data Binding Overview.</p> </blockquote> <p>It would be inefficient to design a system that notifies an entire object graph anytime any property of any subproperty (of any subproperty, of any subproperty, ...) changes. So instead you should use Data Binding to specific properties when you need to do something when that property changes, or if you really want to be notified when <em>any</em> subproperty changes, you should implement <strong>INotifyPropertyChanged</strong>.</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms743695.aspx" rel="nofollow">How to: Implement Property Change Notification</a></p> <p>Example:</p> <pre><code>public class DPGroup : DependencyObject, INotifyPropertyChanged { public static readonly DependencyProperty MyProperty1Property = DependencyProperty.RegisterAttached( "MyProperty1", typeof(int), typeof(DPGroup), new PropertyMetadata(1)); public int MyProperty1 { get { return (int)GetValue(MyProperty1Property); } set { SetValue(MyProperty1Property, value); } } protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); NotifyPropertyChanged(e.Property.Name); } public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } public class DPTest : UserControl { public static readonly DependencyProperty GroupProperty = DependencyProperty.Register( "Group", typeof(DPGroup), typeof(DPTest), new PropertyMetadata( new DPGroup(), new PropertyChangedCallback(OnGroupPropertyChanged) ) ); public DPGroup Group { get { return (DPGroup)GetValue(GroupProperty); } set { SetValue(GroupProperty, value);} } 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(); } private void group_PropertyChanged(object sender, PropertyChangedEventArgs e) { this.UpdateTextBox(); } private void UpdateTextBox() { this.textBox1.Text = this.Group.MyProperty1.ToString(); } private TextBox textBox1; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload