Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: bind to an object's property; what happens when the object changes?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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