I've tested your latest minimized project. The problem here is that the checkDataBaseConnection
method is a an async method and in your code you didn't wait for it to complete. So it's possible that when LoadChartContents
method is executed, the database file has not been copied to LocalFolder. Thus, an error will occur in LoadChartContents
method.
To solve this problem, I'd suggest you wait for the checkDataBaseConnection
method and navigate to "main" page only when the database exists.
For example, we can change checkDataBaseConnection
method like following:
public static async Task<bool> checkDataBaseConnection()
{
if (null == await ApplicationData.Current.LocalFolder.TryGetItemAsync("sale.db"))
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("sale.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder, "sale.db", NameCollisionOption.ReplaceExisting);
}
return true;
}
And in "root" page, take advantage of OnNavigatedTo method like:
public root()
{
this.InitializeComponent();
PassedData.passSplit = MySplitView;
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var result = await myDatabase.checkDataBaseConnection();
if (result)
{
MyFrame.Navigate(typeof(main1));
}
}