Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to listen DataContext change to adjust UI state accordingly
    text
    copied!<p>This question is taking roots from discussion inside <a href="https://github.com/slodge/MvvmCross/issues/367" rel="nofollow">https://github.com/slodge/MvvmCross/issues/367</a> thread. </p> <p>If we're following the recent examples of setting up Bindings with MvvmCross framework then we just setup bindings to control properties (like UILabel.Text) using Bind(), To() extensions:</p> <pre class="lang-cs prettyprint-override"><code>this.DelayBind(() =&gt; { var set = this.CreateBindingSet&lt;KittenCollectionCell, Kitten&gt;(); set.Bind(NameLabel).To(kitten =&gt; kitten.Name); set.Bind(PriceLabel).To(kitten =&gt; kitten.Price); set.Bind(_loader).To(kitten =&gt; kitten.ImageUrl); set.Apply(); }); </code></pre> <p>(taken from <a href="https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-11-KittenView_Collections/KittenView.Touch/Views/KittenCollectionCell.cs" rel="nofollow">https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-11-KittenView_Collections/KittenView.Touch/Views/KittenCollectionCell.cs</a>)</p> <p>But what if I want to adjust my UI state basing on some values from DataContext. For example I would like to show/hide some buttons and labels and to adjust some constraint values.</p> <pre class="lang-cs prettyprint-override"><code>if (((UserInfo)DataContext).IsAdmin) { SaveButton.Hidden = false; SecurityLabelConstraint.Constant = 50; /* etc */ } </code></pre> <p>How I can listen DataContext change event? What's the recommended approach here?</p> <p>Thanks.</p>
 

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