Skip to content Skip to sidebar Skip to footer

Event When Xamarin Page Is Fully Loaded?

community. In advance, I apologize if this really has a simple solution. I have a troublesome problem, considering my skill level with Xamarin, that I need to get resolved. The pro

Solution 1:

You can use custom renderer of ContentPage to know if the view is fully loaded and then use MessagingCenter to notify your shared project:

In iOS:

[assembly:ExportRenderer (typeof(ContentPage), typeof(CameraPageRenderer))]
namespaceApp362.iOS
{
    publicclassCameraPageRenderer : PageRenderer
    {

        publicoverridevoidViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            Console.WriteLine("ViewDidAppear");

            MessagingCenter.Send<object>(newobject(), "ViewLoaded");

        }

    }     
}

In Android:

[assembly: ExportRenderer(typeof(ContentPage), typeof(CameraPageRenderer))]
namespaceApp362.Droid
{
    [Obsolete]
    publicclassCameraPageRenderer : PageRenderer{

        protectedoverridevoidOnAttachedToWindow()
        {
            base.OnAttachedToWindow();

            Console.WriteLine("OnAttachedToWindow");

            MessagingCenter.Send<object>(newobject(), "ViewLoaded");
        }
    }

}

In Shared project:

publicpartialclassMainPage : ContentPage
{
    publicMainPage()
    {
        InitializeComponent();
    }

    protectedoverridevoidOnAppearing()
    {
        base.OnAppearing();
        Console.WriteLine("OnAppearing");

        MessagingCenter.Subscribe<object>(newobject(), "ViewLoaded", (sender) =>
        {
            // Do something whenever the "ViewLoaded" message is received
            Console.WriteLine("Do something whenever the ViewLoaded message is received");
        });
    }
}

Post a Comment for "Event When Xamarin Page Is Fully Loaded?"