使用Icommand在Listview的ListItem中单击按钮

时间:2015-08-10 12:35:24

标签: android listview xamarin mvvmcross

我在 MvxListView 中有列表项和删除按钮。我想删除单击删除按钮的特定行。如何使用 Icommand实现该点击事件

1 个答案:

答案 0 :(得分:0)

MvxListView扩展为DeleteClick属性:

ICommand DeleteClik;

将此属性绑定到您想要的命令:

local:MvxBind="DeleteClick MyDeleteCommand"

创建一个自定义适配器,该适配器将引用此DeleteClick命令并将其绑定到GetView方法上的查看点击事件:

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));
        }
    }
}