ReactiveUI: Using CanExecute with a ReactiveCommand

前端 未结 2 2038
挽巷
挽巷 2021-01-07 07:33

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

2条回答
  •  不要未来只要你来
    2021-01-07 07:59

    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();
    
    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.

提交回复
热议问题