我已经看到了ReactiveUI: Using CanExecute with a ReactiveCommand的问题,但是我的问题是我有一个字符串属性UniqueID,并且我希望它只在长度等于7的时候执行。我似乎想不出一个不会使程序崩溃的观察者。做这件事的正确而简单的方法是什么?
public class MainViewModel : ReactiveValidatedObject
{
public MainViewModel()
{
RetrieveRecord = new ReactiveAsyncCommand(/* what goes here for CanExecute */);
RetrieveRecord.Subscriber(x => Record = new Record(UniqueId));
// or do we use the method RetrieveRecord.CanExecute()?
// the next line crashes the app
RetrieveRecord.CanExecute(UniqueId.Length == 7);
}
public ReactiveAsyncCommand RetrieveRecord { get; private set; }
string _uniqueId;
public string UniqueId
{
get { return _uniqueId; }
set
{
_clientId = value;
this.RaisePropertyChanged(x => x.UniqueId);
}
}
}发布于 2011-10-22 03:46:50
这样如何:
RetrieveRecord = new ReactiveAsyncCommand(
this.WhenAny(x => x.UniqueId, x => x.Value.Length == 7));https://stackoverflow.com/questions/7854471
复制相似问题