public static IBinding BindValue <TModel>( this BooleanElement view, TModel model, Expression <Func <TModel, bool> > getVal) where TModel : INotifyPropertyChanged { var binding = BindingCore.CreateBinding( view, model, getVal, (v, value) => BindingIos.Apply( () => { if (v.Value != value) { v.Value = value; } })); var prop = (PropertyInfo)((MemberExpression)getVal.Body).Member; EventHandler viewOnValueChanged = (sender, args) => { if (!Equals(view.Value, prop.GetValue(model))) { prop.SetValue(model, view.Value); } }; view.ValueChanged += viewOnValueChanged; return(binding.With(() => view.ValueChanged -= viewOnValueChanged)); }
public static void Apply(this Element parent, Func <bool> operation) { BindingIos.Apply( () => { if (!operation()) { return; } var rootElement = HasParentElement <RootElement>(parent); if (rootElement != null) { try { rootElement.Reload(parent, UITableViewRowAnimation.Fade); } catch (Exception ex) { // For unexplainable reasons, this tends to in rare occasions throw an exception, despite RootElement being present... :/ // If someone would look into this, that would be great! } } }); }