首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReactiveUI:具有非集合属性的CanExecute

ReactiveUI:具有非集合属性的CanExecute
EN

Stack Overflow用户
提问于 2011-10-22 03:42:22
回答 1查看 590关注 0票数 0

我已经看到了ReactiveUI: Using CanExecute with a ReactiveCommand的问题,但是我的问题是我有一个字符串属性UniqueID,并且我希望它只在长度等于7的时候执行。我似乎想不出一个不会使程序崩溃的观察者。做这件事的正确而简单的方法是什么?

代码语言:javascript
复制
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);
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2011-10-22 03:46:50

这样如何:

代码语言:javascript
复制
RetrieveRecord = new ReactiveAsyncCommand(
    this.WhenAny(x => x.UniqueId, x => x.Value.Length == 7));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7854471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档