Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's the business objects responsibility to determine what happens to the other items should one become primary, therefore you need some sort of object which manages the <code>IsPrimary</code> flag. </p> <p>However you do it (custom container type, mediator etc) you need something to mediate the changes</p> <p>e.g. </p> <pre><code>public class Mediator { IList&lt;Contact&gt; _contacts = null; public Mediator(IList&lt;Contact&gt; contacts) { _contacts = contacts; foreach(var c in contacts) { c.PropertyChanged += ContactPropertyChanged; } } private bool _isChanging = false; private void ContactPropertyChanged(object sender, PropertyChangedEventArgs e) { var current = sender as Contact; if(e.PropertyName == "IsPrimary" &amp;&amp; !_isChanging &amp;&amp; current.IsPrimary) { _isChanging = true; foreach(var c in _contacts.Where(x =&gt; x != current) { c.IsPrimary = false; } _isChanging = false; } } } </code></pre> <p>There are probably better ways, like having a container collection (which hooks the propertychanged etc on it's own ... also watch out for the event handlers!)</p> <p>You could write a more generic templated version which fires an overload (so you can easily just subclass to create different mediators etc)</p> <pre><code>public class Mediator&lt;T&gt; { IList&lt;T&gt; _items = null; public Mediator(IList&lt;T&gt; items, params string[] watchedProperties) { ... etc protected virtual OnWatchedPropertyChanged(T sender, string PropertyName) { } } public ContactMediator : Mediator&lt;Contact&gt; { public ContactMediator(IList&lt;Contact&gt; contacts, params string[] watchedProperties) { ... override OnWatchedPropertyChanged(Contact object, string propertyName) { ... etc } </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