老实说,我不知道为什么变量被设置为null。对象被设置,然后一旦我通过DisplayPromptAsync,它就会将对象设置为null。
我不知道该尝试什么,因为我从来没有遇到过这个问题。
这是一个问题的gif。一旦我进入字段并按提交,一个对象就会被重置。
async void OpenContainerItem()
{
// Pause the timer
blnTimerActive = false;
if (SelectedItem != null)
{
if (SelectedItem.intQuanChecked == SelectedItem.intQuantity)
return;
try
{
int intQuantity = 0;
// Ask for quantity
string result = await Application.Current.MainPage.DisplayPromptAsync("Quantity",
"How many " + SelectedItem.objItem.strItemName + " did you count?",
"Okay", cancel: "Cancel",
placeholder: "Quantity",
keyboard: Keyboard.Numeric);
// Check if it's been cancelled
if (result != null)
{
// check if theres nothing entered
if (result == "")
{
// Why tho?
await Application.Current.MainPage.DisplayAlert("Error", "Please enter a quantity.", "Okay");
}
else
{
intQuantity = int.Parse(result);
if (0 > ((SelectedItem.intQuantity - SelectedItem.intQuanChecked) - intQuantity))
{
Application.Current.MainPage.DisplayAlert("Error", "Thats too many items!", "Okay");
Reload();
blnTimerActive = true;
return;
}
modDatabaseUtilities.ContainerItemsPreCheck(SelectedItem.intContainerItemID, intQuantity, strCurrentUser);
Reload();
}
}
}
catch(Exception ex)
{
Application.Current.MainPage.DisplayAlert("Error", "Couldn't process this change. Please try again.", "Okay");
}
}
2条答案
按热度按时间tez616oj1#
@ScottUphus - Is
SelectedItem
bound to aListView
? (If it is bound to anything, you should add thatxaml
in your question.) If so, then its a common problem: xamarin sets it back tonull
when the display layout is refreshed. (I'm not sure the exact "rule" for when it happens. In your case, I suspect the modal interaction causes this.)This is how I solve such issues:
ValidSelectedItem
remembers the non-null item, even if xamarin resets the selection back to null. Use it in code that needs that value.lstz6jyr2#
在DisplayPromptAsync中使用“Okay”或“OK”是否有区别?请尝试在代码中更改它。
这是默认页。DisplayPromptAsync方法: