当我单击“清除”时,我想从选择器和条目中清除保存的数据。但是我单击它,它并不能立即清除。我必须关闭该应用,然后重新打开,这很清楚。我尝试输入空字符串“”,但它给了我错误,然后再次打开它冻结了我的应用程序。
void clearHandle_Clicked(object sender, System.EventArgs e)
{
Settings.ClearAllData();
}
//then added to push empty string but got error
//UIApplication.Main(args, null, "AppDelegate");
void clearHandle_Clicked(object sender, System.EventArgs e)
{
DisplayAlert("EDIT", "Are you sure you want to clear data ", "OK");
nameEntry.Text = "";
nxPicker.SelectedItem = "";
locationPicker1.SelectedItem = "";
locationPicker2.SelectedItem = "";
locationPicker3.SelectedItem = "";
locationPicker4.SelectedItem = "";
locationPicker5.SelectedItem = "";
locationPicker6.SelectedItem = "";
locationPicker7.SelectedItem = "";
locationPicker8.SelectedItem = "";
Settings.ClearAllData();
}
答案 0 :(得分:0)
有趣的Click事件有时会在Xamarin中的Forms和Native委托上运行。因此,建议将清除的请求包装在UI调度程序委托中,如下所示:
void clearHandle_Clicked(object sender, System.EventArgs e)
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(()=>{
Settings.ClearAllData();
});
}
void clearHandle_Clicked(object sender, System.EventArgs e)
{
DisplayAlert("EDIT", "Are you sure you want to clear data ", "OK");
nameEntry.Text = "";
nxPicker.SelectedItem = "";
locationPicker1.SelectedItem = "";
locationPicker2.SelectedItem = "";
locationPicker3.SelectedItem = "";
locationPicker4.SelectedItem = "";
locationPicker5.SelectedItem = "";
locationPicker6.SelectedItem = "";
locationPicker7.SelectedItem = "";
locationPicker8.SelectedItem = "";
Xamarin.Forms.Device.BeginInvokeOnMainThread(()=>{
Settings.ClearAllData();
});
}