I'm creating an app, where I want to know what page is currently shown. Some childpages should not be counted as currentpages, that's why I opted to not look at the last Item of the navigationstack as it wouldn't always be right in my case. Besides, I haven't found a way to subscribe to any collectionchanged event on the navigationstack.
The solution I tried to implement goes as follows: In my ViewModel I have a property (Currentpage) in which the current page is stored. This Property gets overwritten whenever the NavigatedTo event of a page is executed.
private void BasePage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
ViewModel.CurrentPage = this;
}
I was able to solve the problem with the childpages by not subscribing them to the event:
if (shouldChangeCurrentPage)
{
ViewModel.CurrentPage = this;
this.NavigatedTo += BasePage_NavigatedTo;
}
My problem now is, that on IOS, the NavigatedTo Event does not get called if you go back to the last page via the backbutton of the navigationpage. Is there any way to make this work?
I'm creating an app, where I want to know what page is currently shown.
You could try Page.OnAppearing Method in MAUI:
protected override void OnAppearing()
{
base.OnAppearing();
}
When overridden, allows application developers to customize behavior immediately prior to the Page becoming visible.