从带有参数的ICommand派生的类

时间:2015-05-10 11:25:43

标签: c# wpf icommand

我有以下属性:

public ICommand ApplySelectedSearchResultCommand { get { return new RelayCommand(ApplySelectedSearchResult, IsSearchResultSelected); } }

RelayCommand是来自MVVM-mini-“框架”的类,它来自ICommand

public class RelayCommand : ICommand
{
    public RelayCommand(Action execute)
        : this(execute, null)
    {
    }

    public RelayCommand(Action execute, Func<Boolean> canExecute)
    {

        if (execute == null)
            throw new ArgumentNullException("execute");
        _execute = execute;
        _canExecute = canExecute;
    }
}

但是我的方法ApplySelectedSearchResult到目前为止没有参数已经改变并且现在包含在参数中:

protected abstract void ApplySelectedSearchResult(Model primaryModel, Model secondaryModel);

如何更改我的财产?

1 个答案:

答案 0 :(得分:1)

假设,正如您所建议的那样,视图模型具有这些模型,那么您可以创建一个提供参数的无参数方法:

private void ApplySelectedSearchResult()
{
    ApplySelectedSearchResult(primary, secondary);
}

或者将其作为行动代表内联:

new RelayCommand(() => ApplySelectedSearchResult(primary, secondary), IsSearchResultSelected);