title: WPF: bind to an object's property; what happens when the object changes?
body: <p>Let's say you have an object with a property and a control that is binding to a property of that object.  What happens when that object is changed?</p>
  
  <p>For example, ViewModel:</p>
  
  <pre><code>public class TheViewModel : INotifyPropertyChanged
  {
          private TheObjectClass theObject;
          public TheObjectClass TheObject
          {
              get { return theObject; }
              set { theObject = value; 
                    OnPropertyChanged("TheObject"); }
          }
  }
  </code></pre>
  
  <p>The object's class:</p>
  
  <pre><code>public class TheObjectClass : INotifyPropertyChanged
  {
          private ThePropertyClass theProperty;
          public ThePropertyClass TheProperty
          {
              get { return theProperty; }
              set { theProperty= value; 
                    OnPropertyChanged("TheProperty"); }
          }
  }
  </code></pre>
  
  <p>The property's class:</p>
  
  <pre><code>public class ThePropertyClass : INotifyPropertyChanged
  {
          private object objectToBindTo;
          public object ObjectToBindTo
          {
              get { return objectToBindTo; }
              set { objectToBindTo= value; 
                    OnPropertyChanged("ObjectToBindTo"); }
          }
  }
  </code></pre>
  
  <p>And then in a window (that has the ViewModel set as it's DataContext) you have a control that binds to this object, like:</p>
  
  <pre><code>&lt;TextBlock Text={Binding TheObject.TheProperty.ObjectToBindTo}/&gt;
  </code></pre>
  
  <p>Then you reset ViewModel.TheObject somewhere (after the binding has been made):</p>
  
  <pre><code>ViewModel.TheObject = new TheObjectClass();
  </code></pre>
  
  <p>In my testing (not specifically of this code, which is just a simplified example of the code in my application) it seems that sometimes the Binding survives, and sometimes it stops working.  What should I expect to happen here?  It seems logical to me that the property binding would break when the parent object is instantiated to a different object, but sometimes it seems to survive which is really confusing me.</p>