在从列表视图中删除项目之前,我有一个Displayactionsheet供确认。
var action = await DisplayActionSheet("Delete Item !", "Yes", "No", "Press YES to delete item");
Debug.Write(action);
if (action.Equals("Yes"))
{
var image = sender as ImageButton;
var item = image?.BindingContext as Product_Value2;
var vm = BindingContext as ItempageVM;
vm?.Delete.Execute(item);
}
else if (action.Equals("No"))
{
}
如果我选择“是”或“否”,则我得到了期望的结果。当我在此框外按下时,显示此错误:
Attempted to finish an input event but the input event receiver has already been disposed.
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
如何处理此异常?
答案 0 :(得分:1)
如果您在外面按,则动作为null,因此您可以检查null并做您想做的事
var action = await DisplayActionSheet("Delete Item !", "Yes", "No", "Press YES to delete item");
if(action == null)
{
//Your logic here
}
else if (action.Equals("Yes"))
{
var image = sender as ImageButton;
var item = image?.BindingContext as Product_Value2;
var vm = BindingContext as ItempageVM;
vm?.Delete.Execute(item);
}
else if (action.Equals("No"))
{
}