Description
openedon Oct 9, 2024
Description
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyGrid.Loaded += async (_, _) => { await Shell.Current.DisplayAlert("Loaded", "Loaded", "OK"); };
MyGrid.Unloaded += async (_, _) => { await Shell.Current.DisplayAlert("Unloaded", "Unloaded", "OK"); };
}
private async void OnCounterClicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(nameof(TestPage1));
}
}
When I navigate into this MainPage, Loaded event is called once, as expected.
When I navigate away from the page by clicking the button, Loaded event is called again, and Unloaded event is call called twice.
I've got an action that is only required to be run on actual navigation into the page (I cannot use Appearing due to the view not being loaded at that point). So the question is, how can I avoid loaded being called when navigating away from the page? If this is a bug, is there a practical way for the function running for the loaded event to tell if I am navigating in or out? So I can ignore it if it is out.
Steps to Reproduce
- Create a brand new project with two pages
- Add above code to the main page
- Run the app and try to navigate away from the page
Note, it is not a Grid specific issue, same problem with StackLayouts, Labels etc.
Link to public reproduction project repository
No response
Version with bug
8.0.91 SR9.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
No response
Affected platforms
iOS
Affected platform versions
iOS 17
Did you find any workaround?
No response
Relevant log output
No response