Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mvvm 使用参数绑定命令_Mvvm_Xamarin_Xamarin.ios_Mvvmcross - Fatal编程技术网

Mvvm 使用参数绑定命令

Mvvm 使用参数绑定命令,mvvm,xamarin,xamarin.ios,mvvmcross,Mvvm,Xamarin,Xamarin.ios,Mvvmcross,在我的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

在我的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
}
var set=this.CreateBindingSet();
set.Bind(Button1).To(vm=>vm.EditCommand).WithConversion(新的MvxCommandParameterValueConverter(),1);
set.Apply();
视图模型:

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
}
private只读ICommand editCommand;
公共MyViewModel()
{
editCommand=newbasemvxcommand(DoEditPhoto);
}
公共ICommand EditCommand{get{return EditCommand;}}
私有void DoEditPhoto(int-imageNum)
{
//在这里输入代码
}

当我按下按钮时,我无法执行
DoEditPhoto()
。我用错误的方式装订吗?有人能帮我吗?

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

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

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

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

什么是BaseMvxCommand可能重复?BaseMvxCommand是MvxCommand类。此问题与该问题不重复,因为该问题的答案建议使用我已在使用但不起作用的命令参数。BaseMvxCommand可能与BaseMvxCommand重复?BaseMvxCommand是MvxCommand类。这个问题与那个问题不一样,因为这个问题的答案建议使用我已经使用过的命令参数,但它不起作用。在这里效果很好。你的BaseMvxCommand一定出了什么问题。在这里工作正常。您的BaseMvxCommand一定做错了什么。