Note that there are some explanatory texts on larger screens.

plurals
  1. POItem in Model does not update in View in real-time
    text
    copied!<p>In my project, I have a view where a user can see ImageCollections which have subfolders and images (set up through MVVM and models). One of the features I wanted to implement is a little image holder where the next image unseen yet is displayed. I have set it up in the ImageCollection model below and it works a treat BUT: it does not update in real-time.</p> <p>What i mean is that when I do click an image as being viewed, the ShowNextToWatchImage Image does not update automatically in the view (it does show the correct new one if I exit the app and relaunch it or when I reopen the folder).</p> <p>How can I fix this?</p> <p><strong>In the model:</strong></p> <pre><code>public Image ShowNextToWatchImage { get { var found = false; Image nextToWatchImage = null; foreach (var folder in Folders) { foreach (var image in folder.Images) { if (!image.ImageHasBeenViewed) { nextToWatchImage = image; found = true; break; } nextToWatchImage = image; } if (found) { break; } } return nextToWatchImage; } set { _showNextToWatchImage = value; NotifyOfPropertyChange(() =&gt; ShowNextToWatchImage); } } </code></pre> <p><strong>EDIT:</strong></p> <p>After trying to implement Sheridan's answer, I have the following (which I am sure I balzed up in some way) which give me nothing (or at least shows nothing in the view for that item.</p> <pre><code>public class Collection : PropertyChangedBase { private Image _showNextToWatchImage; public Collection() { Folders = new List&lt;Folder&gt;(); } public Image ShowNextToWatchImage { get { return _showNextToWatchImage; } set { _showNextToWatchImage = value; UpdateNextToWatchImage(); NotifyOfPropertyChange(() =&gt; ShowNextToWatchImage); } } public void UpdateNextToWatchImage() { var found = false; Image nextToWatchImage = null; foreach (var folder in Folders) { foreach (var image in folder.Images) { if (!image.ImageHasBeenViewed) { nextToWatchImage = image; found = true; break; } nextToWatchImage = image; } if (found) { break; } } ShowNextToWatchImage = nextToWatchImage; } public List&lt;Folder&gt; Folders { get; set; } } </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