UWP帧导航.是否可以在后台加载视图



我有一个类似幻灯片的东西这里的代码:

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++;
}
}

但问题是,我使用Grafana,当我加载视图ChartWheaterPage时,Grafana加载20-30秒。有没有一种方法可以在启动时加载页面,并显示它只加载一次

有没有一种方法可以在启动时加载页面并显示它只加载一次?

让我们先解决后一个问题,让页面只初始化一次。

默认情况下,每次导航时,应用程序都会创建一个新页面,如果您想重用该页面,可以缓存该页面,以便下次导航时首先使用缓存的页面。

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

在此基础上,如果您的某个页面需要长时间加载,并且不是幻灯片的第一页,则可以考虑在应用程序启动时跳到此页面,然后跳到初始页面。

由于您跳转到页面并启用了缓存,因此页面将继续加载。当您在20-30秒后转到该页面时,该页面已加载并可以显示。

谢谢。

最新更新