public async Task <MainViewModel> Init() { await Task.Run(async() => { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; try { _dataFile = await storageFolder.GetFileAsync("App1Database.xaml"); _database = (App1Data)XamlServices.Load(_dataFile.Path); } catch (FileNotFoundException) { // Create sample file; var data = new App1Data { IntData = 83, NetWorth = 100000000001.99M, SomeStringData = "One Hundred Billion Dollars... and some change." }; StorageFile sampleFile = await storageFolder.CreateFileAsync("App1Database.xaml", CreationCollisionOption.ReplaceExisting); using (var stream = new FileStream(sampleFile.Path, FileMode.Truncate)) { XamlServices.Save(stream, data); } } }); MyInt = _database.IntData; NetWorth = _database.NetWorth; TextProperty = _database.SomeStringData; return(this); }
public async Task<MainViewModel> Init() { await Task.Run(async () => { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; try { _dataFile = await storageFolder.GetFileAsync("App1Database.xaml"); _database = (App1Data) XamlServices.Load(_dataFile.Path); } catch (FileNotFoundException) { // Create sample file; var data = new App1Data { IntData = 83, NetWorth = 100000000001.99M, SomeStringData = "One Hundred Billion Dollars... and some change." }; StorageFile sampleFile = await storageFolder.CreateFileAsync("App1Database.xaml", CreationCollisionOption.ReplaceExisting); using (var stream = new FileStream(sampleFile.Path, FileMode.Truncate)) { XamlServices.Save(stream, data); } } }); MyInt = _database.IntData; NetWorth = _database.NetWorth; TextProperty = _database.SomeStringData; return this; }