我正在嘗試向用戶顯示警報對話框。我試圖通過在代碼隱藏(About.xaml.cs)類中定義一個方法并從 ViewModel(myViewModel.cs)類中呼叫它來實作這一點。但這不起作用。DisplayAlert 在其他事件處理程式方法中運行良好。
關于.xaml.cs
public void RadioButton_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
DisplayAlert("hello", "test", "Yes", "No"); //working
RadioButton rb = sender as RadioButton;
gender = rb.Content as string;
}
public async Task<bool> DisplayConfirmation(string title, string msg)
{
return await DisplayAlert(title, msg, "Yes", "No"); //not working
}
我的視圖模型.cs
async void deleteStudentRecord(int id)
{
About about = new About();
if (await about.DisplayConfirmation("Alert!", "Are you sure?"))
{
try
{
int deleted_count = await DBServices.DeleteRecord(id);
await Refresh();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
}
如果有人解釋這種行為并展示正確的方法,那將非常有幫助。提前致謝!
uj5u.com熱心網友回復:
您可以使用 App Context 使用 Like 下面,
Application.Current.MainPage.DisplayAlert("hello", "test", "Yes", "No")
謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/414634.html
標籤:
下一篇:由于Manage_External_Storage,應用程式在Play商店中被拒絕,即使我的應用程式沒有使用此權限
