.Net Maui, how to run method after page is shown?

Phunction 301 Reputation points
2023-02-05T22:31:22.9633333+00:00

Hi, I am trying to find a way to run a method after a contentpage is showing on the screen.

OnAppearing() does not work as it fires before the page is actually loaded. Is there any way to do this without using a timer?

It seems strange there is no built in method for this, unless I am missing something.

I show the page with Navigation.PushAsync

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,955 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,313 questions
{count} vote

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 48,666 Reputation points Microsoft Vendor
    2023-02-06T03:05:21.8766667+00:00

    Hello,

    Hi, I am trying to find a way to run a method after a contentpage is showing on the screen.

    Lifecycle functions that are triggered after a page is fully loaded are not yet included in MAUI.

    In fact, there is a Loaded event in MAUI that fires the moment your control is creating.

    Occurs when a VisualElement has been constructed and added to the object tree. This event may occur before the VisualElement has been measured so should not be relied on for size information.

    You could use this event as the following code:

    YouControl.Loaded += (s, e) => {        };
    

    Please refer to VisualElement.Loaded Event to get more details.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.