在我的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()
。我是以错误的方式绑定的吗?任何人都可以帮助我吗?
答案 0 :(得分:3)
是的,你的绑定在技术上没有错。但是,您不需要转换器将参数传递给绑定的ICommand
。为此,您可以在链中使用CommandParameter
:
set.Bind(Button1).To(vm => vm.EditCommand).CommandParameter(ViewModel.ImageNumber);