Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Is there a way to speed up XAML Page loading?

$
0
0

I'm writing a Xamarin Forms solution for Android and iOS. The application uses a Master-Detail menu where each menu item is a page to navigate to, very simple. My problems is that when tapping on a menu item the application takes several seconds to create and navigate to the new page. My pages are XAML pages with many combinations of views (stack-layouts, grids, labels, etc). To make the UI responsive I'm using a separate thread to load and switch to the new page while I enable a wait animation. Still, it seems to me that there has to be a better way to navigate to new pages. User should not have to wait a long time to move into a new application screen. Is Xamarin Forms simply slow to load new pages, or Am I doing this incorrectly? Is it better to create all the application's pages during the application startup, or use some other way?

Here is a simplified example of how I'm navigating to new pages:

public async void NavigateTo(MenuItem menu)
    {
        await Task.Yield();

        if (menu == null)
        {
            IsPresented = false;
            return;
        }
        else
        {
            // Switch Page
            menu.BusyLoading = true; // Enable wait animation
            ThreadPool.QueueUserWorkItem (o => LoadPage(menu));
        }            
    }

    /// <summary>
    /// Loads the page. This function takes a long time to load the new page
    /// </summary>
    /// <param name="menu">Menu.</param>
    private void LoadPage(MenuItem menu)
    {
        // Create new content page
        Page displayPage = (Page)Activator.CreateInstance(menu.TargetType /* This is basically my new ContentPage object */);

        Device.BeginInvokeOnMainThread(() =>
            {
                Detail = new NavigationPage(displayPage);

                menu.BusyLoading = false;
                IsPresented = false;
            });
    }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>