Hello,
Welcome to our Microsoft Q&A platform!
I've noticed that when CrossMedia.Current.PickPhotoAsync(...) is called, the OnAppearing function is called on the main page.
The OnAppearing method will be called when the page becomes visible, picking a file will level the current page. That is why OnAppearing method will be called after selecting an image. We cannot prevent the OnAppearing method being called. Instead, it's available to skip the function code in the OnAppearing method.
Try to create a status property in the page class and detect the value to skip the function code. Check the code:
public partial class TestPage : ContentPage
{
bool theValue;
public TestPage()
{
InitializeComponent();
...
}
private async void Button_Clicked(object sender, EventArgs e)
{
//pick the file
theValue = true;
}
protected override void OnAppearing()
{
base.OnAppearing();
if (theValue)
return;
DisplayAlert("title", "message", "cancel");
theValue = false;
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.