英文:
Navigationpage NavigatedTo event not working on IOS when going back - Maui
问题
我正在创建一个应用程序,在其中我想知道当前显示的页面是哪个。某些子页面不应被视为当前页面,这就是为什么我选择不查看导航堆栈的最后一个项目,因为在我的情况下它并不总是正确。此外,我还没有找到一种订阅导航堆栈上任何集合更改事件的方法。
我尝试实现的解决方案如下:在我的ViewModel中,我有一个属性(Currentpage),用于存储当前页面。每当页面的NavigatedTo事件执行时,此属性都会被覆盖。
private void BasePage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
ViewModel.CurrentPage = this;
}
我成功解决了子页面的问题,方法是不订阅它们的事件:
if (shouldChangeCurrentPage)
{
ViewModel.CurrentPage = this;
this.NavigatedTo += BasePage_NavigatedTo;
}
现在我的问题是,在iOS上,如果通过导航页面的返回按钮返回到上一页,NavigatedTo事件不会被调用。有没有办法让它正常工作?
英文:
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?
答案1
得分: 1
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.
英文:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论