我在MVXListView中有带有删除按钮的列表项。我要删除单击了删除按钮的特定行。如何使用ICommand实现该单击事件?

最佳答案

扩展MvxListView以具有DeleteClick属性:
ICommand DeleteClik;
将此属性绑定到所需的命令:

local:MvxBind="DeleteClick MyDeleteCommand"

创建一个自定义适配器,该适配器将引用此DeleteClick命令,并将其绑定到GetView方法上视图的click事件:
public override View GetView (int position, View view, ViewGroup parent)
{
    //TODO: Ensure view is not null, call base method and convert to proper type
    var deleteButton = view.FindViewById<Button>(Resource.Id.buttonId);

    deleteButton.Click += (sender, e) => {
        if(_deleteCommand != null && _deleteCommand.CanExecute())
        {
            //TODO: Cast to your type
            _deleteCommand(GetRawItem(position));
        }
    }
}

09-09 21:15