async Task ReadRecipeBook() { StorageFolder localFolder = ApplicationData.Current.LocalFolder; try { // Getting JSON from file if it exists, or file not found exception if it does not StorageFile textFile = await localFolder.GetFileAsync("recipeFile.txt"); using (IRandomAccessStream textStream = await textFile.OpenReadAsync()) { // Read text stream using (DataReader textReader = new DataReader(textStream)) { //get size uint textLength = (uint)textStream.Size; await textReader.LoadAsync(textLength); // read it string jsonContents = textReader.ReadString(textLength); // deserialize back to our product! List <RecipeClass> recipe_Current = JsonConvert.DeserializeObject <List <RecipeClass> >(jsonContents); // and show it foreach (RecipeClass recipe in recipe_Current) { RecipeCard_Image newRecipeCard = new RecipeCard_Image(); newRecipeCard.RecipeID = recipe.ID.ToString(); newRecipeCard.Name = recipe.ID.ToString(); newRecipeCard.RecipeTitle = recipe.Name; newRecipeCard.RecipeDescription = recipe.Description; newRecipeCard.RecipeImage = ""; newRecipeCard.HorizontalAlignment = HorizontalAlignment.Center; newRecipeCard.VerticalAlignment = VerticalAlignment.Center; if (grid_desktab.Visibility == Visibility.Collapsed) { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var size = bounds.Width; var sizeMin = size - 50; newRecipeCard.Width = sizeMin; Recipe_FlipView.Items.Add(newRecipeCard); } else { newRecipeCard.MinWidth = 450; Recipe_FlipView_Desktab.Items.Add(newRecipeCard); } } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); // Exceptions everywhere } }
private void newCard(string ID, string Title, string Descrition, ImageBrush Image) { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var size = bounds.Width; var sizeMin = size - 50; RecipeCard.Width = sizeMin; RecipeCard_Image newRecipeCard = new RecipeCard_Image(); newRecipeCard.RecipeID = "000000001"; newRecipeCard.Name = newRecipeCard.RecipeID; newRecipeCard.RecipeTitle = "Created Title"; newRecipeCard.RecipeDescription = "Write this down because it exists."; newRecipeCard.RecipeImage = ""; newRecipeCard.Width = sizeMin; newRecipeCard.HorizontalAlignment = HorizontalAlignment.Center; newRecipeCard.VerticalAlignment = VerticalAlignment.Center; Recipe_FlipView.Items.Add(newRecipeCard); }