I have the following ViewModel
class MyViewModel
{
private string _name;
public MyViewModel()
{
CommitChanges = ReactiveCommand.Create(Observable.When(
this.ObservableForProperty(x => x.Name)
.And(Childs.CountChanged)
.Then((one, two) => !string.IsNullOrWhiteSpace(one.Value) && two > 0)));
CommitChanges.Subscribe(_ => DoCommitChanges());
}
public IReactiveList Childs { get ; } = new ReactiveList<object>();
public string Name
{
get { return _name; }
set { this.RaiseAndSetIfChanged(ref _naam, value); }
}
public ReactiveCommand<object> CommitChanges { get; }
private void DoCommitChanges() { ... }
}
The CanExecute
of the CommitChanges command isn't following the observables correctly. For example when I add a child and set the name to something the CanExecute
changes to true
as expected, but when I then clear the name the CanExecute
still stays true
. What am I doing wrong?