我需要根据结果集检查app.xaml.cs文件中的条件主页,但我得到内部不一致异常。请建议动态设置主页面的任何想法。提前谢谢。
以下是我的示例代码:
public App()
{
InitializeComponent();
_loginView = new SampleView();
InitializePage();
}
private async void InitializePage()
{
await LocalDatabaseService.Instance.Initialize();
var applicationEntity = await LocalDatabaseService.Instance.GetUserApplicationRecord();
MainPage = applicationEntity != null ? new NavigationPage(new SampleTwo()) : new NavigationPage(_loginView);
}
答案 0 :(得分:1)
The MainPage
property should be set in the App constructor
由于InitializePage
以异步方式运行,MainPage
不会立即在App
的构造函数中设置。我建议将构造函数中的MainPage
设置为中间人" loading"页面,然后在您完成初始化后替换它。