Windows Phone 8 JumpStart: Contoso Cookbook Step 6, Page Navigation

This sample was demo 1 in Module 3 of the Windows Phone 8 JumpStart: Building Windows Phone Apps. In previous samples in this series, the pages of the Contoso Cookbook project were designed. In this step, page navigation is added to navigate from one page to another.

C# (4.5 MB)
 
 
 
 
 
(0)
2,186 times
Add to favorites
12/20/2012
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using ContosoCookbook.Resources;
using ContosoCookbook.Data;

namespace ContosoCookbook
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }


        private Microsoft.Phone.Shell.ProgressIndicator pi;

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (!App.Recipes.IsLoaded)
            {
                pi = new Microsoft.Phone.Shell.ProgressIndicator();
                pi.IsIndeterminate = true;
                pi.Text = "Loading data, please wait...";
                pi.IsVisible = true;

                Microsoft.Phone.Shell.SystemTray.SetIsVisible(this, true);
                Microsoft.Phone.Shell.SystemTray.SetProgressIndicator(this, pi);

                App.Recipes.RecipesLoaded += Recipes_RecipesLoaded;
                App.Recipes.LoadLocalDataAsync();
            }
            base.OnNavigatedTo(e);
        }

        void Recipes_RecipesLoaded(object sender, EventArgs e)
        {
            lstGroups.DataContext = App.Recipes;

            pi.IsVisible = false;
            Microsoft.Phone.Shell.SystemTray.SetIsVisible(this, false);
        }

        private void lstGroups_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstGroups.SelectedItem != null)
            {
                NavigationService.Navigate(new Uri("/GroupDetailPage.xaml?ID=" + 
                    (lstGroups.SelectedItem as RecipeDataGroup).UniqueId, UriKind.Relative));
            }
        }
    }
}