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