private void MainPivot_LoadingPivotItem(object sender, PivotItemEventArgs e)
 {
     RefreshCurrentPivotItem();
     secondsString = exercise.Time.ToString();
     if (exercise.Machine.Type == MachineType.Cardio)
     {
         cardioPage = currentPivotItem.Content as CardioTrainingPage;
         setTimerRemaining = TimeSpan.FromSeconds(exercise.Time);
         cardioPage.setTimerValue.Text = setTimerRemaining.ToString(@"mm\:ss");
         //MessageBox.Show(exercise.ExerciseName);
     }
 }
        private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
        {
            exercises = DataAccess.GetRoutineExercises(Data.Instance.currentRoutine.Id);

            foreach (Exercise ex in exercises)
            {
                PivotItem newPiv = new PivotItem();
                newPiv.Header = ex.ExerciseName;
                newPiv.Tag = Convert.ToString(i);
                i++;
                if (ex.Machine.Type == MachineType.Cardio)
                {
                    cardioPage = new CardioTrainingPage();
                    cardioPage.txt_Time.Text = ex.Time.ToString();
                    cardioPage.txt_level.Text = ex.Reps_Level.ToString();
                    BitmapImage bitmapImage = new BitmapImage(new Uri(ex.Icon, UriKind.Relative));
                    cardioPage.image1.Source = bitmapImage;
                    cardioPage.setTimerButton.Click += new RoutedEventHandler(setTimerButton_Click);
                    cardioPage.setTimerResetButton.Click += new RoutedEventHandler(setTimerResetButton_Click);
                    cardioPage.skipButton.Click += new RoutedEventHandler(skipButton_Click);
                    cardioPage.image1.DataContext = ex;
                    newPiv.Content = cardioPage;
                }
                else
                {
                    liftPage = new LiftTrainingPage();
                    liftPage.txt_Reps.Text = ex.Reps.ToString();
                    liftPage.txt_Sets.Text = ex.Sets.ToString();
                    liftPage.txt_Weight.Text = ex.Weight.ToString();
                    BitmapImage bitmapImage = new BitmapImage(new Uri(ex.Icon, UriKind.Relative));
                    liftPage.image1.Source = bitmapImage;
                    liftPage.skipButton.Click += new RoutedEventHandler(skipButton_Click);
                    newPiv.Content = liftPage;
                }

                MainPivot.Items.Add(newPiv);
            }
            MainPivot.SelectedIndex = int.Parse(newparameter);
            startExercise();
        }
 private void RefreshCurrentPivotItem()
 {
     currentPivotItem = MainPivot.SelectedItem as PivotItem;
     //exercise = exercises[MainPivot.SelectedIndex];
     exercise = exercises[int.Parse(Convert.ToString(currentPivotItem.Tag))];
     if (exercise.Machine.Type == MachineType.Cardio)
     {
         cardioPage = currentPivotItem.Content as CardioTrainingPage;
     }
     else
     {
         liftPage = currentPivotItem.Content as LiftTrainingPage;
     }
 }