Appearing Event is not getting called

Viewed 67

Whenever I navigate to a page via Shell.Current.GoToAsync("Page"); the cross platform event "Appearing" is getting triggered in "Page". The "Appearing" event is also getting triggered when I pop to "Page" via Shell.Current.Navigation.PopAsync();.

But when I push a page modal onto "Page" via Shell.Current.Navigation.PushModalAsync(new Page2()); and then pop this "Page2" with Shell.Current.Navigation.PopModalAsync(); in "Page2" then the "Appearing" event is not getting triggered in "Page".
Does someone know if this is intendet or if it is a Bug?
If this is not a Bug, is there a way to register when "Page" is Appearing or in focus again so I can do something then?

Steps to reproduce:

Shell.Current.GoToAsync("Page")

In "Page":

Shell.Current.Navigation.PushModalAsync(new Page2());

In "Page2":

Shell.Current.Navigation.PopModalAsync();

=> Lifecycle Event Appearing is not getting triggered in "Page".

3 Answers

It's not a bug, when you push a modal,alert or a popup (with community toolkit), the main page who invoke that it's still there, so you couldn't trigger appearing method.

Solution 1: EventTriggers

<ContentPage.Triggers>
    <EventTrigger Event="LayoutChanged" >
        YourTriggerThatFocusHere
    </EventTrigger>
</ContentPage.Triggers>

Layout changed event is fired after and before you push a modal so you could use it in this way. And in your local trigger you set the focus on the control you want with "controlname".Focus()

Solution 2 (for MVVM) if you need to fire a command you could use eventToCommand behavior with the same layout changed event:

         xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

<ContentPage.Behaviors>
    <toolkit:EventToCommandBehavior EventName="LayoutChanged"
                                    Command="{Binding YourCommand}" />
</ContentPage.Behaviors>

This is a bug, This is only a issue on Android, works fine on iOS.

Found out that it is an already registered Bug.

Githubticket

Related