Пример #1
0
 public MyViewModel(MyModel model)
 {
     _model                  = model;
     _myProperty             = new Computed <string>(() => _model.MyModelProperty);
     _myPropertySubscription = _myProperty.Subscribe(_ =>
                                                     NotifyOfPropertyChange(() => MyProperty));
 }
Пример #2
0
 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);
             }
         }
     });
 }