I\'m starting to work with the ReactiveUI framework on a Silverlight project and need some help working with ReactiveCommands.
In my view model, I have something tha
I finally figured this one out. Using ReactiveCommand.Create()
worked for my situation.
MyViewModel()
{
AddNewRecord = ReactiveCommand.Create(x => MyCollection.Count < MaxRecords);
AddNewRecord.Subscribe(x =>
{
MyCollection.Add("foo");
}
}
Actually, there's a better way to do this, change your ObservableCollection to ReactiveCollection (which inherits from ObservableCollection but adds some extra properties):
MyCollection = new ReactiveCollection<string>();
AddNewRecord = new ReactiveCommand(
MyCollection.CollectionCountChanged.Select(count => count < MaxRecords));
The catch here now is though, you can't overwrite the MyCollection, only repopulate it (i.e. Clear() + Add()). Let me know if that's a dealbreaker, there's a way to get around that too though it's a bit more work.