public MyViewModel(MyModel model) { _model = model; _myProperty = new Computed <string>(() => _model.MyModelProperty); _myPropertySubscription = _myProperty.Subscribe(_ => NotifyOfPropertyChange(() => MyProperty)); }
public PropertyValidator(string propertyName, Func <object> function, Action <string> notify) { PropertyName = propertyName; _validationErrors = new Computed <List <string> >(() => { var value = function(); return(_rules.Select(r => r(value)).Where(e => e != null).ToList()); }); _subscription = _validationErrors.Subscribe((errors, priorErrors) => { if (priorErrors == null) { if (errors != null && errors.Any()) { notify(propertyName); } } else { if (errors == null || !priorErrors.SequenceEqual(errors)) { notify(propertyName); } } }); }