Esempio n. 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            int index = -1;

            if (e.Parameter == null)
            {
                recipes = App.recipes;
                int numRecipes = recipes.getRecipeList().Count;
                if (numRecipes > 0)
                {
                    index = 0;
                }
            }
            else
            {
                recipes = (RecipeList)e.Parameter;
                index   = recipes.getSelectedIndex();
            }
            this.recipeListView.ItemsSource = recipes.Recipes;

            if (index < 0)
            {
                detailFrame.Visibility = Visibility.Collapsed;
            }
            recipeListView.SelectedIndex = index;

            updateLayoutFromState(AdaptiveStates.CurrentState, null);
            Debug.WriteLine(index);
            showDetailView(index);
        }
Esempio n. 2
0
        private void showDetailView(object sender, ItemClickEventArgs e)
        {
            Recipe r         = (Recipe)e.ClickedItem;
            int    itemIndex = 0;

            if (r != null)
            {
                itemIndex = recipes.getRecipeList().IndexOf(r);
            }

            showDetailView(itemIndex);
        }
Esempio n. 3
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);
                }
            }
        }