【问题标题】:Bind command with parameters使用参数绑定命令
【发布时间】:2017-01-26 04:32:59
【问题描述】:

在我的 Xamarin iOS 项目中,我想将一个按钮绑定到一个带有参数的 ICommand。

查看:

var set = this.CreateBindingSet<MyView, MyViewModel>();
set.Bind(Button1).To(vm => vm.EditCommand).WithConversion(new MvxCommandParameterValueConverter(), 1);
set.Apply();

视图模型:

private readonly ICommand editCommand;
public MyViewModel()
{
   editCommand = new BaseMvxCommand<int>(DoEditPhoto);
}

public ICommand EditCommand { get { return editCommand; } }
private void DoEditPhoto(int imageNum)
{
    // enter code here
}

当我点击按钮时,我无法执行DoEditPhoto()。我是否以错误的方式绑定?谁能帮帮我?

【问题讨论】:

  • 什么是 BaseMvxCommand?
  • BaseMvxCommnad 是 MvxCommand 类。该问题与该问题不重复,因为该问题的答案建议使用我已经在使用但不起作用的命令参数。

标签: mvvm xamarin xamarin.ios mvvmcross


【解决方案1】:

是的,您的绑定在技术上没有错。但是,您不需要转换器 将参数传递给绑定的ICommand。为此,您可以在链中使用CommandParameter

set.Bind(Button1).To(vm => vm.EditCommand).CommandParameter(ViewModel.ImageNumber);

【讨论】:

  • 在这里工作正常。你的 BaseMvxCommand 一定做错了什么。
猜你喜欢
  • 2015-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-07
  • 2019-12-25
  • 2015-07-29
  • 1970-01-01
相关资源
最近更新 更多