Note that there are some explanatory texts on larger screens.

plurals
  1. PONotifying my UI to refresh when a collection in it's VM changes
    primarykey
    data
    text
    <p>I have a usercontrol bound to a VM. This VM contains a collection property, lets call it "MyCollection" and several regular properties lets call one of them "SomeProperty". As you can see, the get and set logic for this property references the collection in the VM.</p> <p>The problem is, when I make a change to "MyCollection", this obviously has an impact on the values that are shown in the UI (as they are calculated based on it). However, my UI doesn't appear to be smart enough to update itself whenever "MyCollection" changes.</p> <p>Here is the VM my usercontrol is bound to:</p> <pre><code>public class MyVM { private ObservableCollection&lt;SomeOtherVM&gt; _myCollection = new ObservableCollection&lt;SomeOtherVM&gt;(); public MyVM() { } public ObservableCollection&lt;SomeOtherVM&gt; MyCollection { get { return _myCollection; } [Notify] set { _myCollection = value; } } public virtual string SomeProperty { get { if (_myCollection.Count == 1) return _myCollection[0].SomeProperty; else return "More than one "SomeOtherVM" has been selected"; } [Notify] set { foreach (SomeOtherVM s in _myCollection) { s.SomeProperty = value; } } } } </code></pre> <p>}</p> <p>Note that nothing in my usercontrol is directly bound to the collection, it is only bound to other properties that reference the collection in its get; set; methods.</p> <p>Is there anything I could do in the VM to force the UI to update whenever "MyCollection" is changed? I want to avoid having to put anything in the code behind for the user control.</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