Issue
I am trying to show the Alert dialog to the user. I am trying to achieve this by defining a method in the code-behind(About.xaml.cs) class and calling it from ViewModel(myViewModel.cs) class. But this is not working. DisplayAlert is working fine in other event handler methods.
About.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
}
myViewModel.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);
}
}
}
It will be very helpful if someone explains this behavior and show the right method to do it. Thanks in advance!
Solution
you can use Like Below using App Context,
Application.Current.MainPage.DisplayAlert("hello", "test", "Yes", "No")
Thanks
Answered By - Krunal Bagadia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.