Search code examples
c#.netuwpframegrafana

UWP Frame Navigation. Is it possible to load a view in background?


I have something like a slideshow Here the code:

private int index;
        private List<Type> pages = new List<Type>() { typeof(ChartWheaterPage), typeof(ChartServerPage), typeof(mitarbeiteronlinePage), typeof(MomentaneKundenPage), typeof(OutlookKalenderPage), typeof(fdösjf), typeof(ChartZielPage) };
        public MainPage()
        {

            this.InitializeComponent();
            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(20);
            timer.Tick += Timer_Tick;
            timer.Start();

        }


            private void Timer_Tick(object sender, object e)
            {
                grid_loading.Opacity = 0;
                if (index == pages.Count)
                {
                    index = 0;
                }
                this.contentFrame.Navigate(pages[index]);
                index++;
            }

    }

but the problem is that I use Grafana and when I load the view ChartWheaterPage Grafana loads 20-30 seconds. Is there a way to load the page on startup and show it that it only loads one time


Solution

  • Is there a way to load the page on startup and show it that it only loads one time?

    Let ’s solve the latter problem first and let the page initialize only once.

    By default, the application will create a new page every time you navigate, and if you want to reuse the page, you can cache the page so that the next time you navigate, the cached page will be used first.

    public MyPage()
    {
        this.InitializeComponent();
        NavigationCacheMode = NavigationCacheMode.Enabled;
    }
    

    On this basis, if one of your pages needs to load for a long time and is not the first page of the slide, you can consider jumping to this page when the application starts, and then jump to the initial page.

    Since you jumped to the page and enabled the cache, the page will continue to load. When you go to the page after 20-30 seconds, the page has been loaded and can be displayed.

    Thanks.