OnAppearing of Page called again, although this page was on already replaced NavigationStack
Description
Starting from MainPage(1), when clicking a button I put a page on navigation stack. OnAppearing of this page(2) triggers an process in my app (in bug-repo it shows a display alert). Clicking the button on the page replaces the navigation stack by another page (3). Clicking the button on this page navigates to MainPage(1), but calling the OnAppearing-Event of the page(2).
Steps to Reproduce
Checkout + Build Repo Click on the button on each view to perform the navigation that produces the issue A display alert is shown when "Select Device Page" is shown (the first time its okay) After showing MainPage again the display alert is shown again (which it should not).
Link to public reproduction project repository
https://github.com/messemaSICKAG/BugRepoOnAppearingCall
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
Unknown/Other
Affected platforms
Android, Windows
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
There is no bug at this place. The page is appearing, so OnAppearing is raised. If you want the behavior you describe, replace your code by:
private bool firstAppearing = true;
private void SelectDevicePage_OnAppearing(object? sender, EventArgs e)
{
if (firstAppearing)
{
DisplayAlert("SelectDevicePage", "... appeared", "Ok");
firstAppearing = false;
}
}
Okay, I updated the repo to make the point more clear. Of course the view should appear, but only once. The problem is that 'OnAppearing' is called again when the App shows a complete different page (in this case the MainPage again).
Startup --> MainPage shown --> SelectDevicePage On NavigationStack (OnAppearing called the first time) --> DeviceSpecificPage - NavigationStack replaced --> MainPage - NavigationStack replaced (OnAppearing of SelectDevicePage called the second time)
private int _appearingCount;
private void SelectDevicePage_OnAppearing(object? sender, EventArgs e)
{
if(_appearingCount > 0)
{
DisplayAlert("SelectDevicePage", "... appeared more than once", "Ok");
}
_appearingCount++;
}
I can repro this issue at Android platform on the latest 17.12.0 Preview 2.1(8.0.90 & 8.0.91).
The issue is not reproduced with the latest MAUI version (10.0.20) on Android, iOS, MacCatalyst and Windows platforms. Related PR: https://github.com/dotnet/maui/pull/32582
Hi @@messemaSICKAG. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.