コード例 #1
0
        private async void tryDeleteRecipe(Recipe recipeToDelete)
        {
            ContentDialog deleteConfirmationDialog = new ContentDialog
            {
                Title   = "Permenantly delete recipe?",
                Content = "If you delete this recipe, you won't be" +
                          " able to recover it. Are you Sure you want to delete" +
                          " it?",
                PrimaryButtonText = "Delete",
                CloseButtonText   = "Cancel"
            };

            ContentDialogResult result = await deleteConfirmationDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                int deleteIndex = recipes.getRecipeList().IndexOf(recipeToDelete);

                if (deleteIndex > 0)
                {
                    // deleting recipe somewhere other than beginning
                    // select the recipe before it
                    recipes.SelectedIndex = deleteIndex - 1;
                }
                else if (deleteIndex == 0)
                {
                    // deleting recipe at the beginning
                    // select the same index
                    recipes.SelectedIndex = 0;
                }

                recipes.removeRecipe(recipeToDelete);
                if (isNarrow())
                {
                    Frame.GoBack();
                }
                else
                {
                    if (recipes.Recipes.Count == 0)
                    {
                        // hide this column
                        detailSectionGrid.Visibility = Visibility.Collapsed;
                    }
                    selectedRecipe             = recipes.getSelected();
                    detailSection.SelectedItem = detailSection.MenuItems[0];
                    contentFrame.Navigate(typeof(DetailPage), selectedRecipe);
                }
            }
        }