/// <summary> /// Initializes a new instance of the <see cref="CF.Xamarin.Forms.Classes.PropertyChangeListener"/> class. /// </summary> /// <param name="owner">Owner.</param> /// <param name="callback">Callback.</param> public void Listen <TModel>(Expression <Func <TModel, object> > property, object owner, Action callback) { if (callback == null) { throw new ArgumentNullException("callback"); } if (owner == null) { throw new ArgumentNullException("owner"); } _notifyChangedObject = owner as INotifyPropertyChanged; if (_notifyChangedObject == null) { throw new ArgumentNullException("owner as IPropertyNotifyChanged"); } _propertyName = PropertyNameHelper.GetPropertyName <TModel>(property); if (string.IsNullOrEmpty(_propertyName)) { throw new ArgumentException("property"); } _callback = callback; // Hook up event _notifyChangedObject.PropertyChanged += HandlePropertyChangedEventHandler; // Start by updating: _callback(); }
/// <summary> /// Calls the notify property changed event if it is attached. By using some /// Expression/Func magic we get compile time type checking on our property /// names by using this method instead of calling the event with a string in code. /// </summary> /// <param name="property">Property.</param> protected override void RaisePropertyChangedEvent(Expression <Func <object> > property) { base.RaisePropertyChangedEvent(property); var propertyName = PropertyNameHelper.GetPropertyName <BaseModel>(property); CheckDependantProperties(propertyName); }
/// <summary> /// Adds a dependency between a property and another property. Whenever the property changes, the command's /// state will be updated /// </summary> /// <param name="property">Source property.</param> /// <param name="dependantProperty">Target property.</param> private void AddPropertyDependency(Expression <Func <object> > property, Expression <Func <object> > dependantProperty) { AddPropertyDependency(PropertyNameHelper.GetPropertyName <BaseModel>(property), PropertyNameHelper.GetPropertyName <BaseModel>(dependantProperty)); }
/// <summary> /// Returns the name of the member /// </summary> /// <returns>The of.</returns> /// <param name="prop">Property.</param> public string NameOf <TModel>(Expression <Func <TModel, object> > property) { return(PropertyNameHelper.GetPropertyName <TModel> (property)); }
/// <summary> /// Calls the notify property changed event if it is attached. By using some /// Expression/Func magic we get compile time type checking on our property /// names by using this method instead of calling the event with a string in code. /// </summary> /// <param name="property">Property.</param> protected virtual void RaisePropertyChangedEvent(Expression <Func <object> > property) { RaisePropertyChangedEvent(PropertyNameHelper.GetPropertyName <BaseNotifyPropertyChangedObject>(property)); }